json POST

Hello, below is a sample code of data I am trying to post and receive a response.  I would like to do this in PHP but I am not sure how to? If not jQuery would be fine. Any help would be greatly appreciated..Not sure where to start..

POST https://securegateplus.nmp.neuroticmedia.net/Customer/Register HTTP/1.1
api-key: B6FFF46B-9557-42F0-AB88-2FA53C098E84
User-Agent: Fiddler
Host: securegateplus.nmp.neuroticmedia.net
Content-Length: 462
Content-Type: application/json; charset=utf-8
{
"Customer":
{
"UserName":"testers@neuroticmedia.com"
}
}

Open in new window

bradley525Asked:
Who is Participating?
 
bradley525Connect With a Mentor Author Commented:
I figured out how to get it to work....


//////////////////BIRTHDAY////////////////////////////////
$birth = date('1980-01-01');
$objDateTime = new DateTime($birth);
$date=$objDateTime->format('U');
$date=$date."000"; //add milliseconds required by sitefinity

/////////////////////////////Agreed To Terms/////////////////////////
$agreed_date = date('Y-m-d');;
$aobjDateTime = new DateTime($agreed_date);
$adate=$aobjDateTime->format('U');
$adate=$adate."000"; //add milliseconds required by sitefinity


/////////////////////////ALL THE DATA BELOW IS REQUIRED OR AN ERROR WILL OCCUR////////////////////////////////
$data = 
array( "BillingAddress" => array("PostalCode"=>"xxxxx"),
"Customer" => array(
"CellPhone"=>"xxx-555-1212",
"FirstName"=>"Brad",
"AgreedTermsDate"=>"/Date(".$adate.")/",
"DateOfBirth"=>"/Date(".$date.")/",
"LastName"=>"xxxxxx",
"Password"=>"xxxxxx",
"UserName"=>"levi@xxxxxx.com")); 
       
///////////////////////CONVERT THE ARRAY TO json//////////////////////////////	                                                               
$data_string = json_encode($data);                                                                                   
$ch = curl_init('https://securegateplus.nmp.neuroticmedia.net/Customer/Register');

//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(   
	'api-key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',                                                                 
    'Content-Type: application/json; charset=utf-8',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                       
);                                                                                                                   

$result = curl_exec($ch);

//print_r($result);

/////////////////////////CONVERT THE RESULTS INTO AN ARRAY//////////////////////////////
$assocArray = json_decode($result, true);

////SHOW the customer ID////////////////////////
echo $assocArray['CustomerID'];	

Open in new window

0
 
Alexandre SimõesManager / Technology SpecialistCommented:
If it's jQuery and an ajax POST should be something like:
$.ajax({
type:'POST',
url: 'https://securegateplus.nmp.neuroticmedia.net/Customer/Register',
data: {"customer": { "UserName" : "testers@neuroticmedia.com" }},
success: function(){ // handle success },
error: function(){ // handle error }
})

Open in new window


Otherwise (and I'm not a PHP guy) but the idea should be the same as any other <form> POST.
<form action="https://securegateplus.nmp.neuroticmedia.net/Customer/Register" method="post">
        <input name="customer.UserName" type="text" value="testers@neuroticmedia.com" />
        <input name="mySubmit" type="submit" value="submit" />
</form>

Open in new window

0
 
Ray PaseurCommented:
Do you have the documentation that tells what to send to the API?  If so, please post it here or post a link to it, thanks.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
Chris StanyonCommented:
You'll only be able to do it with jQuery if the remote server supports JSONP (if not you could push it through a proxy), but as Ray says, without documentation we'll be guessing all day long.

As for PHP, you're probably best off looking a cURL.

We're gonna need more info
0
 
bradley525Author Commented:
Here is the API..I am working off of page 10 right now..
0
 
bradley525Author Commented:
forgot to attach...Here it is...Thanks
Neurolinq-Plus-API-v1.1--1-.pdf
0
 
Ray PaseurCommented:
Sorry, I just don't have time to read a 62-page API manual.  Is there any kind of a "quickstart" guide or another way we could get to the SSCCE?
0
 
bradley525Author Commented:
Sorry .thanks for the help..But I am not asking you to read to 62 pages...I am just on page 10 trying to get the request on the bottom of page 10 to work..thanks
0
 
Ray PaseurCommented:
OK, that shrinks the footprint a bit.  Look at page 1 of the PDF document.  It describes a RESTful access method.  That is what I would recommend.  I'll look at it a little bit more.  While I am doing that, please read this article:
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_12239-Introduction-to-Application-Programming-Interfaces.html
0
 
Ray PaseurCommented:
It looks like you would want to make a cURL POST-method request to this URL:
https://securegateplus.nmp.neuroticmedia.net/Customer/Register

I can't test this, but it may help to get you started.  You might also want to consider fsockopen() to communicate with the API.

<?php // RAY_curl_post_async.php
error_reporting(E_ALL);


// DEMONSTRATE HOW TO USE CURL POST TO START AN ASYNCHRONOUS PROCESS


function curl_post
( $url
, $header
, $post_string
, $timeout=2
, $error_report=FALSE
)
{
    // PREPARE THE CURL CALL
    $curl = curl_init();
    curl_setopt( $curl, CURLOPT_URL,            $url         );
    curl_setopt( $curl, CURLOPT_HEADER,         $header      );
    curl_setopt( $curl, CURLOPT_POST,           TRUE         );
    curl_setopt( $curl, CURLOPT_POSTFIELDS,     $post_string );
    curl_setopt( $curl, CURLOPT_TIMEOUT,        $timeout     );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, TRUE         );

    // EXECUTE THE CURL CALL
    $htm = curl_exec($curl);
    $err = curl_errno($curl);
    $inf = curl_getinfo($curl);

    // ON FAILURE
    if (!$htm)
    {
        // PROCESS ERRORS HERE
        if ($error_report)
        {
            echo "CURL FAIL: $url TIMEOUT=$timeout, CURL_ERRNO=$err";
            echo "<pre>\n";
            var_dump($inf);
            echo "</pre>\n";
        }
        curl_close($curl);
        return FALSE;
    }

    // ON SUCCESS
    curl_close($curl);
    return $htm;
}


// PREPARE THE JSON STRING
$jso = <<<EOD
{
"BillingAddress":
  {
  "AddressName":"Billing",
  "City":"Newnan",
  "PostalCode":"30076",
  "Province":"GA",
  "Street1":"487 Gibson Rd"
  },
"Customer":
  {
  "AgreedTermsDate":"\/Date(1297110939057-0500)\/",
  "CellPhone":"678-777-3454",
  "DateOfBirth":"\/Date(200462400000-0400)\/",
  "FirstName":"Tim",
  "LastName":"Kohler",
  "MerchantID":"28908a45-750c-4ac6-81e3-98d7a0c889b0",
  "Password":"password",
  "UserName":"testers@neuroticmedia.com"
  }
}
EOD;


// PREPARE THE HEADERS
$hdr[] = 'api-key: B6FFF46B-9557-42F0-AB88-2FA53C098E84';
$hdr[] = 'User-Agent: Fiddler'; // NOT SURE IF THIS MATTERS
$hdr[] = 'Content-Length: ' . strlen($jso);
$hdr[] = 'Content-Type: application/json; charset=utf-8';


// MAKE THE CALL
$resp = curl_post('https://securegateplus.nmp.neuroticmedia.net/Customer/Register', $hdr, $jso, 3, TRUE);
var_dump($resp);

Open in new window

HTH, ~Ray
0
 
bradley525Author Commented:
Thank you, but the result says FAIL


CURL FAIL: https://securegateplus.nmp.neuroticmedia.net/Customer/Register TIMEOUT=3, CURL_ERRNO=52
array(22) {
  ["url"]=>
  string(62) "https://securegateplus.nmp.neuroticmedia.net/Customer/Register"
  ["content_type"]=>
  NULL
  ["http_code"]=>
  int(0)
  ["header_size"]=>
  int(0)
  ["request_size"]=>
  int(624)
  ["filetime"]=>
  int(-1)
  ["ssl_verify_result"]=>
  int(0)
  ["redirect_count"]=>
  int(0)
  ["total_time"]=>
  float(0.123081)
  ["namelookup_time"]=>
  float(0.002697)
  ["connect_time"]=>
  float(0.019398)
  ["pretransfer_time"]=>
  float(0.100394)
  ["size_upload"]=>
  float(461)
  ["size_download"]=>
  float(0)
  ["speed_download"]=>
  float(0)
  ["speed_upload"]=>
  float(3745)
  ["download_content_length"]=>
  float(-1)
  ["upload_content_length"]=>
  float(461)
  ["starttransfer_time"]=>
  float(0.123016)
  ["redirect_time"]=>
  float(0)
  ["certinfo"]=>
  array(0) {
  }
  ["redirect_url"]=>
  string(0) ""
}
bool(false)

Open in new window

0
 
bradley525Author Commented:
The other solutions were on track, but they did not work. The above solution is tested and works.
0
 
Chris StanyonCommented:
The fact that the other solutions were on track means you should have accepted them as assisted solutions - you only got to where you got to because of the Experts help, so it's only right that you acknolwedge that!!
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.

All Courses

From novice to tech pro — start learning today.