I have an access key to an API, which allows me to obtain data about products (such as price, description, etc).
I am aware of 2 manual ways to use this key:
1) Use the "modify headers" firefox addon, insert the key in the headers, and then type the URL that will yield an XML file (https://api.domain.com/search?parameter=something
), and I will see an output tree like this:
<manufacturer-name>SONY</manufacturer-name> <price>99.99</price>
Along with another 20 fields.
2) Use PHP file with this code:
$myHeaders = array("key: code"); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.domain.com/search?parameter=something"); curl_setopt($ch, CURLOPT_HTTPHEADER,$myHeaders); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); $returnResult = curl_exec($ch); if ($returnResult) { //parse HTTP Body to determine result of request if (stripos($returnResult,"Error Code ")) { // error occurred trigger_error($returnResult,E_USER_ERROR); } else{ // success echo $returnResult; } } else{ // connection error trigger_error(curl_error($ch),E_USER_ERROR); } curl_close($ch);
And then I see this output:
SONY 99.99
My question:
Using same PHP code, how can I request only the price
field to show up?
(I ask this because later on, I will want my server to make auto requests like this, and update my own database with the current values of these fields).
No comments:
Post a Comment