How to get data from API

confis

Member
Hi ,

I am try to get the value from this XML (value1,value2) from URL

<ArrayOfstring xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><string>value1</string><string>value2</string></ArrayOfstring>

I have tried to use the below on filed with eval - yes

$xml = json_decode(file_get_contents('api_url'));
return $xml ;

also try this

$xml = SimpleXmlElement(file_get_contents('api_url'));
return ($xml->values);


But with no help ;(

do you have any advice how to make it work?

Thanks
Yaniv
 
Try to debug, something like
$x =file_get_contents(...);
var_dump($x);exit;

or use the extension J!Dump
 
If that var_dump() isn't showing anything, then that file_get_contents() probably isn't returning anything.

It would help if you could give us the URL you are pulling data from.

-- hugh
 
This works for me ...

Code:
$content = file_get_contents('https://shamirpapi.com:444/PAPI/values');
$json = json_decode($content);

$json is then an array. not sure what you want to do with it. If you wanted to return it as a comma separated string ...

Code:
return implode(',', $json);

You could probably simplexml_load_string($content) if you wanted to do xml-ish stuff with it.

-- hugh
 
A details view of a non-existing record is always empty.
And you still didn't mention where you are using this code (calc element, element default, custom template, validiation condition,... there are many places)
 
A default is evaluated only in the form when you are adding a new record.

A details view is showing what is stored in the database after you have added (and saved) the record.

So if you are showing the details view of an non-existing record (as with your link) you'll see nothing
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top