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
bradley525Asked:
Who is Participating?
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.

Ray PaseurCommented:
Can you please post a link to the API documentation?  You can almost certainly read it with cURL or maybe with file_get_contents()
0
bradley525Author Commented:
I was emailed the API documentation it is not readily available for download on the web.
0
Ray PaseurCommented:
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?
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

bradley525Author Commented:
The URL is in the code above...Thats about all I know...Thus far..
0
Julian HansenCommented:
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.
0
Ray PaseurCommented:
Please see: http://www.laprbass.com/RAY_temp_bradley525.php

You should be able to add your credentials, according to the documentation for the API, and just run this script.  I'm fairly sure the 403 response makes sense without the credentials.

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

$url = 'https://securegateplus.nmp.neuroticmedia.net/Product/fae8bc6e-f31e-466c-9889-230fbc9e6a54';
$dat = file_get_contents($url);
var_dump($dat);

Open in new window

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
bradley525Author Commented:
Hi Ray, how do I add my cridentials?
0
Ray PaseurCommented:
I have no idea.  That would be part of the documentation for the API, I expect.
0
Julian HansenCommented:
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.
0
bradley525Author Commented:
After reviewing the API I was able to get this working..thank you..
0
Ray PaseurCommented:
Thanks for the points -- glad you got it working! ~Ray
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
PHP

From novice to tech pro — start learning today.