Link to home
Start Free TrialLog in
Avatar of bradley525
bradley525

asked on

XML GET Request using PHP and json

Hello I am using an api that gave me the following example information.  I am not sure how to build a function that can send the request and print the results..The information below is not my real data... I am hoping to use PHP to do this..

GET https://securegateplus.nmp.neuroticmedia.net/Product/fae8bc6e-f31e-466c-9889-230fbc9e6a54 HTTP/1.1
api-key: B6FFF46B-9557-42F0-AB88-2FA53C098E84
User-Agent: Fiddler
Host: securegateplus.nmp.neuroticmedia.net
Content-Type: application/json; charset=utf-8

Open in new window



Thanks
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Can you please post a link to the API documentation?  You can almost certainly read it with cURL or maybe with file_get_contents()
Avatar of bradley525
bradley525

ASKER

I was emailed the API documentation it is not readily available for download on the web.
OK, what does it say about how to access the API?  Or what is the URL of the API?  Any other hints you can give us so we can show you how to set up a test case in PHP code?
The URL is in the code above...Thats about all I know...Thus far..
Avatar of Julian Hansen
You will need something like this

function submitRequest($url, $key)
{
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url);
    
    // Setup $postfields here
    // Requires API documentation
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    $output = curl_exec ($ch);         
        
    curl_close ($ch);

    return $output;
}
$url = 'https://securegateplus.nmp.neuroticmedia.net/Product/fae8bc6e-f31e-466c-9889-230fbc9e6a54';
$key = "Key goes here but don't publish on public forums";

$response = json_decode(submit($url, $key);

Open in new window


The above is a sample - it won't work for you. We would need the api to be able to give you working code.

Somewhere in the API it will explain how to submit a request. This could be in the form of key value pairs posted to the URL or as an XML package with required parameters.

Without knowing what they are expecting to receive on the API side we cannot advise you further.

What the code above will do is make a server to server request - posting the data in $postfields to the remote server and retrieving the result sent back.

The final line will decode the returned JSON string into a PHP object.

If you need further assistence you will need to give us some info about how the API works.
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Ray, how do I add my cridentials?
I have no idea.  That would be part of the documentation for the API, I expect.
Hi Ray, how do I add my cridentials?
Please see my earlier post - without the API documentation we can't tell you this.

Its like saying I have just bought a new phone - how do I set the date and time.

Although the supplier of the information is providing a RESTful interface - how they have implemented their interface is documented in their API.
After reviewing the API I was able to get this working..thank you..
Thanks for the points -- glad you got it working! ~Ray