API - overwrite existing file in site

I’m working on a file distribution where a file with parameters gets periodically sent down to the endpoints.

I’m using curl to post the file to the site and distribute to the targets which works great:

curl -k -H "ISClientFile: 1" -X POST -F "file=@\_Temp\myfile.csv" "https://servername:52311/api/site/custom/mysite/files"

The issue I have is when I want to replace that file with a new version, I can’t seem to find a way to overwrite:

Attempt to create a file on site 'mysite' with the same name 'myfile.csv' of one already existing.

I could do a GET to retrieve the file ID, and then do a DELETE to remove it before re-posting the new file…but there must be a way to invoke overwrite instead?

When you do this manually via the console “Add files to site…” under tools you get an overwrite option.

Hi,

In my testing you can use a PUT on the file ID to replace it. This means you have to query the existing file ID first and then do a REST PUT to /<Site>/File/ID to replace the file.

Bill

check if the thread Difference between Put and Post in IEM CLI can help You