0

I've this cUrl

curl -X POST \
 -H "Authorization: Key {api-key}" \
 -H "Content-Type: application/json" \
 -d '
 {
"inputs": [
  {
    "data": {
      "image": {
        "url": "https://samples.clarifai.com/metro-north.jpg"
      }
    }
  }
]
}'\
https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs

I want to make Post request with PHP so i can get json response. I've tried this:

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
     CURLOPT_HTTPAUTH => $token,
      CURLOPT_POSTFIELDS => $img_url,
    CURLOPT_URL => 'https://api.clarifai.com/v2/models/aaa03c23b3724a16a56b629203edc62c/outputs',
    CURLOPT_USERAGENT => 'Codular Sample cURL Request'
));

But this doesn't work. Any help would be greatly appreciated.

Error:

array(1) { ["status"]=> array(3) { ["code"]=> int(11102) ["description"]=> string(15) "Invalid request" ["details"]=> string(28) "Malformed or invalid request" } }
Daman
  • 473
  • 2
  • 7
  • 17
  • 2
    What does It mean "doesn't work"? Do you retrieve some errors? – Alessandro Minoccheri Jul 11 '17 at 07:28
  • It seems like you forgot to set `Authorization` and `Content-Type` headers in your code. As for the `$img_url` variable we cannot tell if it's correct when you don't show us the contents. And you may also need to add `CURLOPT_POST => true` to your config array. – Jirka Hrazdil Jul 11 '17 at 07:31
  • @AlessandroMinoccheri This is what i get on var_dump array(1) { ["status"]=> array(3) { ["code"]=> int(11102) ["description"]=> string(15) "Invalid request" ["details"]=> string(28) "Malformed or invalid request" } } – Daman Jul 11 '17 at 19:10

0 Answers0