Jump to content

php and API call


Richard Yates

Recommended Posts

Trying to hook up to an API using php. The API commands are sent in url query strings. Depending on the command you are sending in the query string, the API returns an XML file or text. For commands that return an XML file I can use $response=simplexml_load_file($APIcall) and parse and store the xml that comes back into $response.

 

But with text responses from the API I cannot find a way to handle the reply. Using xml_load_file() results in errors displayed since it was expecting xml and nothing gets stored in $response, although the command is correctly executed by the API. I can use headers('Location: $APIcall') but that just gets the text response sent to a new window. $response=get_headers($APIcall) works for some commands but still does not capture the text response.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/251002-php-and-api-call/
Share on other sites

I'm assuming $APIcall is the URL that you need to access and then get the results?

 

Use file_get_contents() to access the URL and download the results (regardless of if it is text or xml).  If it is an XML response, then do further processing with simplexml_load_string().

 

Link to comment
https://forums.phpfreaks.com/topic/251002-php-and-api-call/#findComment-1287625
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.