Level up your Box knowledge with brand new learning paths on Box University. Visit training.box.com to get started

Update File Info using cUrl script

Répondu
Nouvelle publication

Commentaires

12 commentaires

  • kendomen

    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.

     

    curl -k https://api.box.com/2.0/files/> -H "Authorization: Bearer " -d '{"description":"New Description55"}' -X PUT

    0
    Actions pour les commentaires Permalien
  • zizou21

    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.

    0
    Actions pour les commentaires Permalien
  • LoCortes

    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:

     

    curl -k https://api.box.com/2.0/files/> -X PUT -H "Authorization:Bearer XXX" -H "Content-Type:application/json" -d '{"description":"NewDefinition"}'

     

    It should be '{"description":"NewDefinition"}'

     

    Regards

    0
    Actions pour les commentaires Permalien
  • zizou21

    @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.

    0
    Actions pour les commentaires Permalien
  • zizou21

    I am wondering if the API works of if I missing something ?

     

    Thanks for your help.

    0
    Actions pour les commentaires Permalien
  • LoCortes

    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: 

     

    curl -k https://api.box.com/2.0/files/> -X PUT -H "Authorization:Bearer XXX" -H "Content-Type:application/json" -d '{"description":"NewDefinition"}'

     

    Good luck.

    0
    Actions pour les commentaires Permalien
  • zizou21

    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.

    0
    Actions pour les commentaires Permalien
  • zizou21

    I found a workaround.

    0
    Actions pour les commentaires Permalien
  • aebrey

    What was the work around? Can you please your solution

    0
    Actions pour les commentaires Permalien
  • sandokan87

    What was the workaround?

    0
    Actions pour les commentaires Permalien
  • ksendhil

    Could you please share the solution/workaround?

    0
    Actions pour les commentaires Permalien
  • MattEB

    double-quotes in json data need to be escaped with a backslash to be used in curl.

     

    https://community.box.com/t5/Platform-and-Development-Forum/Error-renaming-folder-name-via-Update-Folder-using-cURL/m-p/62229/highlight/true#M5344

    0
    Actions pour les commentaires Permalien

Vous devez vous connecter pour laisser un commentaire.