I have created the following code to get specifics products by title:
$url = "https://xxxxxxx@xxxxx/admin/api/2020-04/products.json?title=ADAGIO%GOLD"; $session = curl_init(); curl_setopt($session, CURLOPT_URL, $url); curl_setopt($session, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $json2 = json_decode($response); var_dump($json2);
But I get NULL.
What is the problem??
Solved! Go to the solution
1-The product title is ADAGIO GOLD, and i try with ADAGIO GOLD and ADAGIO%GOLD but I get error with the both names.
2-When i do the call with Postman i get the correct product, but when i do the call with the PHP code i get NULL [var-dump(json2) = NULL]
3-How can i print the headers?
4- I only get NULL with the var_dump.
This is an accepted solution.
So my hunch says that you're using % when you actually mean the HTML encoded space character which is:
So the name then would be:
Try that as the URL, e.g:
$url = "https://xxxxxxx@xxxxx/admin/api/2020-04/products.json?title=ADAGIO%20GOLD";
And see if that works?
Sorry PHP not my strong suit.