Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Unable to get data from API


Go to End


573 Views

Avatar
VPull

Community Member, 58 Posts

24 April 2017 at 6:52pm

Hello,

I am facing problem to get data from API, when I request API URL in local srver (WAMP) it gives error

[User Error] Uncaught Exception: String could not be parsed as XML

and same code on live server (Linux hosting) give a different error

[Warning] SimpleXMLElement::__construct(): Entity: line 1: parser error : Start tag expected, '<' not found

API developer said I am getting a JSON response from the webservice
To get an XML response, please send the HTTP header Content-Type = text/xml

so I modify code like

$service = new RestfulService('my-api-url');

$service->httpHeader('Content-Type: text/xml');
      
// perform the query
$conn = $service->request();

// parse the XML body
$msgs = $service->getValues($conn->getBody(), "results");

Still I am getting the same errors, is there anything that I am doing wrong?

Thanks in advance