• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

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.
0
soujohn
Asked:
soujohn
  • 2
2 Solutions
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now