Update File in the Library

These instructions are for updating a file in the library via the API. If you're looking to update a file in the library as a regular user, see Editing and updating files.

As with all PUT (update) requests to the KnowledgeOwl API, the ID of the object you are wanting to update will need to be specified as part of the URL endpoint. In this case, the URL endpoint will look like: 

https://app.knowledgeowl.com/api/head/file/<<file_id>>.json 

However, due to some constraints on how KnowledgeOwl's backend infrastructure works, uploading a new file via the API to replace an existing file must be sent as a POST request instead of a PUT.

In order to signify that the request should be treated as a PUT (update) despite being sent as a POST (create), the parameter "_method=PUT" must be included within the POST body.

If "_method=PUT" is missing from the request body, the API will return an error, because object IDs should not normally be included in POST requests.

If the request is sent as a PUT request instead of POST, the file meta data such as the "name" field will be updated, but the file content itself will be untouched.

Here is an example of what a file update might look like using a tool like Postman:

Sample file update in Postman

Here is an example of what a CURL request might look like:

curl -u <<api_key>>:x -X POST 'https://app.knowledgeowl.com/api/head/file/5xxxxxxxxxxxxxxxxxxx.json' \
--form 'project_id=5xxxxxxxxxxxxxxxxxxxxx' \
--form 'file=@/C:/cropped.jpg' \
--form 'name=gravatar-take-two.png' \
--form '_method=PUT'