Search code examples
box-api

Box.com api - "Does file exist" check


Why doesn't the box api have an "exists" method for files? Seems like a very common use case.

Because there is no direct method, how do you use the API to tell whether or not a file ID exists?


Solution

  • Using the API you can simply request the metadata for the file with that ID. If the file exists and you have access to it, then a full file object will be returned.

    Request:

    curl https://api.box.com/2.0/files/FILE_ID
    -H "Authorization: Bearer ACCESS_TOKEN"
    

    Response:

    200 OK
    
    {
        "type": "file",
        "id": "5000948880",
        "etag": "3",
        "sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc",
        "name": "tigers.jpeg",
        ...
    }