Pregunta

I'm using cURL in PHP to access the Asana API.

I've been happy appending my values to the URL as GET but now, as my app grows larger, I'm posting more and more data, so I've been trying to convert it to post.

So far, I've tried:

setting post['data'] to a json object {key:value,key:value}
setting post['data'] to a json object {options:{key:value,key:value}}
setting post['data'] to a json object {data:{options:{key:value,key:value}}}
setting post['data'] to a json object {data:{key:value,key:value}}
setting post['body'] to all of the above json objects

For my methods so far, I end up with the error:

Could not parse request data, invalid JSON

Using cURL, of course, I'm doing this:

$post = json_encode($myFields);
curl_setopt(CURLOPT_POSTFIELDS,array('data'=>$post));

For all of these tests, I'm outputting the JSON and validating it with JSLint. It's very valid JSON, so the problem definitely isn't that. I just need to know WHY it's not valid.

I just can't quite get it to work. Thanks for any help- Daniel.

¿Fue útil?

Solución

Try to encode in JSON all you array, not only the "data" part :

$post = json_encode(array('data' => $myFields));
curl_setopt(CURLOPT_POSTFIELDS, $post); 

Otros consejos

I made a PHP class wrapper for Asana API. You can grab it here: https://github.com/ajimix/asana-api-php-class

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top