Send logged in user data to third party API via POST method without form submit

Greetings,

I am trying to create a way to send user data to a third Party API (Cvent) without having a logged in site visitor fill out a form.

The API requires a users first name, last name, and email address in order to connect to a event page I create. Only site members will have access to these pages so I should already have the required users info when they register as a site member.

What I would like is to have a button that will collect the logged in users first name, last name, and email then send it to the API via POST method.

I will have to collect and send this info using PHP, but I don’t know how to get that user data. Any help with that would be greatly appreciated.
soujohnAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You can do this client side or serverside with php.  The problem with client side like jquery is if you use any type of authentication to hit the api it will be open for viewing.  

Jquery would be
[code]$.ajax({
  method: "POST",
  url: "https://yourapi.com/some_endpoint",
  data: { name: "John", email: "me@mydomain.com" }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });

Open in new window


If you view the page source and your data has secret keys, you have exposed something you shouldn't have.

Another option is using cURL. http://php.net/manual/en/curl.examples-basic.php
<?php
$params=['name'=>'John', 'email'=>'me@mydomain.com', 'password'=>'abc')
$defaults = array(
CURLOPT_URL => 'https://myremoteservice/', 
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $params,
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
?>

Open in new window


That sample may be over simplified for how you need to deal with your api.  Also check if your api  has an sdk.  If you are using mailchimp or the like there will be some code samples how to do this.
0
Ray PaseurCommented:
should already have the required users info when they register as a site member
This would probably come into your web site via an HTML form, right?  This link will show you how to use the HTML forms and the PHP scripts together.
http://php.net/manual/en/tutorial.php

Following that, you would probably want to store the data in a database or file, just to be sure that it does not get lost if the connection to CVent is interrupted (these things happen more than we would wish).

And finally, you would fire up the CVent API and follow the directions they gave you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
soujohnAuthor Commented:
Thanks for all the feedback. Because the approach I was originally taking didn't seem flexible with collecting/providing enough data for an event registration we've decided to use a complete form for users to fill out rather than only collecting basic information.
0
Ray PaseurCommented:
I think you got pretty good answers, considering the breadth of the question.  Please see the grading guidelines, then help us understand why you gave a marked-down grade instead of engaging in some dialog with the expert community.  Where did we fall down here?
http://support.experts-exchange.com/customer/portal/articles/481419
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.