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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.