Update File Info using cUrl script
AnsweredHello All,
I am trying to update a file (the description) using the following cUrl command :
curl https://api.box.com/2.0/files/file_id -H "Authorization: Bearer_Token" -D {"description":"New Description"} -X PUT -k
When I execute the command I am receiving the display of the current record. And no update is processed.
Can you please recommend the best approach.
Thanks.
-
I was getting what you were seeing so I had to use a lower-case "-d" and add the single quotes around the description values.
-
Hi @kendomen,
I tried your suggestion but I am receiving :
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value ''{description:NewDefinition}''. Entity body should be a correctly nested resource attribute name\/value pair"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"***number removed for privacy***12369854df4963"}
Thanks.
-
Hello ,
you are missing the double quotes before and after the description and NewDefinition. Or better said you forgot the single quote that surrounds the body:
It should be '{"description":"NewDefinition"}'
Regards
-
@LoCortes, ,
I tried the below cURL command (-d, -D, with/without the simple ) but none of them is triggering an update. The -d option is not working. I am executing them from a DOS prompt.
1 - Script=
curl https://api.box.com/2.0/files/file_id -H "Content-Type: text" -H "Authorization: Bearer Bearer_Token" -D {"description":"TestPOCNew"} -X PUT -k
1- Response=
{"type":"file","id":"file_id","file_version":{"type":"file_version","id":"***number removed for privacy***999","sha1":"***number removed for privacy***99999999999999999999999999999"},"sequence_id":"32","etag":"32","sha1":"***number removed for privacy***99999999999999999999999999999","name":"image.tif","description":"Actual Description","size":672708,"path_collection":{"total_count":3,"entries":[{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"},{"type":"folder","id":"***number removed for privacy***99","sequence_id":"2","etag":"2","name":"XXXXXXX DX"},{"type":"folder","id":"***number removed for privacy***99","sequence_id":"1","etag":"1","name":"XXXXXX META"}]},"created_at":"2017-03-24T13:36:19-07:00","modified_at":"2017-04-26T12:54:34-07:00","trashed_at":null,"purged_at":null,"content_created_at":"2017-03-01T05:59:08-08:00","content_modified_at":"2017-03-01T05:59:08-08:00","created_by":{"type":"user","id":"9999999","name":"John Woo","login":"***email address removed for privacy***"},"modified_by":{"type":"user","id":"4798076","name":"John Woo","login":"***email address removed for privacy***"},"owned_by":{"type":"user","id":"99999999","name":"Jean Jones","login":"***email address removed for privacy***"},"shared_link":null,"parent":{"type":"folder","id":"***number removed for privacy***99","sequence_id":"1","etag":"1","name":"XXXXXXX META"},"item_status":"active"}2 -Script=
curl https://api.box.com/2.0/files/file_id -H "Content-Type: text" -H "Authorization: Bearer Bearer_Token" -D '{"description":"TestPOCNew"}' -X PUT -k
2- Response=
{"type":"file","id":"file_id","file_version":{"type":"file_version","id":"***number removed for privacy***999","sha1":"***number removed for privacy***99999999999999999999999999999"},"sequence_id":"32","etag":"32","sha1":"***number removed for privacy***99999999999999999999999999999","name":"image.tif","description":"Actual Description","size":672708,"path_collection":{"total_count":3,"entries":[{"type":"folder","id":"0","sequence_id":null,"etag":null,"name":"All Files"},{"type":"folder","id":"***number removed for privacy***99","sequence_id":"2","etag":"2","name":"XXXXXXX DX"},{"type":"folder","id":"***number removed for privacy***99","sequence_id":"1","etag":"1","name":"XXXXXX META"}]},"created_at":"2017-03-24T13:36:19-07:00","modified_at":"2017-04-26T12:54:34-07:00","trashed_at":null,"purged_at":null,"content_created_at":"2017-03-01T05:59:08-08:00","content_modified_at":"2017-03-01T05:59:08-08:00","created_by":{"type":"user","id":"9999999","name":"John Woo","login":"***email address removed for privacy***"},"modified_by":{"type":"user","id":"4798076","name":"John Woo","login":"***email address removed for privacy***"},"owned_by":{"type":"user","id":"99999999","name":"Jean Jones","login":"***email address removed for privacy***"},"shared_link":null,"parent":{"type":"folder","id":"***number removed for privacy***99","sequence_id":"1","etag":"1","name":"XXXXXXX META"},"item_status":"active"}3 - Script =
curl https://api.box.com/2.0/files/file_id -H "Content-Type: text" -H "Authorization: Bearer Bearer_Token" -d '{"description":"TestPOCNew"}' -X PUT -k
3- Response=
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value ''{description:TestPOCNew}''. Entity body should be a correctly nested resource attribute name\/value pair"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"***number removed for privacy***659023c5ded714"}4- Script=
curl https://api.box.com/2.0/files/file_id -H "Content-Type: text" -H "Authorization: Bearer Bearer_Token" -d {"description":"TestPOCNew"} -X PUT -k
4 - Response=
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value '{description:TestPOCNew}'. Entity body should be a correctly nested resource attribute name\/value pair"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"***card # removed for privacy***c70e5266"}Thanks.
-
Hello ,
the content type must be application/json and you are passing text.
Take this as it is and only change the ID and the token. Do not change the order of any parameters or anything else apart of the and the XXX:
Good luck.
-
Hello @LoCortes,
I followed your sugggestion. I took the query and only changed the ID () and the token (XXX). I did not change the parameters order. But I am receiving the follwing message:
{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value ''{description:NewDefinition}''. Entity body should be a correctly nested resource attribute name\/value pair"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"***number removed for privacy***8590342c62f7cd"}
Thanks.
-
double-quotes in json data need to be escaped with a backslash to be used in curl.
Please sign in to leave a comment.
Comments
12 comments