Updating mobile worker via API

I'm able to update a mobile worker using the API using CURL but only if I supply the json data in a file. I'm unable to pass the same data in-line in the CURL command. I'm getting {"error": "Request is not valid JSON."}

Any ideas what I'm doing wrong?

This works:
curl -u user@mydomain.com:password -X PUT https://www.commcarehq.org/a/my-project/api/v0.5/user/123456abcd12345/ -H "Content-Type: application/json" -d "@data.txt" -L
where data.txt contains the following:

{
"first_name": "John"
}

This does not work:
curl -u user@mydomain.com:password -X PUT https://www.commcarehq.org/a/my-project/api/v0.5/user/123456abcd12345/ -H "Content-Type: application/json" -d '{"first_name":"John"}' -L

I realise this may be Curl related, but I thought I'd ask anyhow in case anyone has any bright ideas.
Thanks!

Hi, @erobinson .

From a little googling it seems like it might even be related to the shell you're using. What happens when you try to escape the double quotes, like below?

curl -u user@mydomain.com:password -X PUT https://www.commcarehq.org/a/my-project/api/v0.5/user/123456abcd12345/ -H "Content-Type: application/json" -d "{\"first_name\":\"John\"}" -L

1 Like

Epic. Easy when you know how haha. Thanks Charl, that did the trick.
I was testing in bash and Windows command line.

1 Like