Feat: can resource api support put function?

Currently, the resource-related joplin api can only create resources, but cannot modify them through the api. Can this be supported so that external tools can update resources?

  1. The vscode plugin creates a temporary file for the resource and updates the resource via the joplin api after modification
  2. Reduce resources such as images in batches


1 Like

Yes I've been meaning to add this for some times, so it will be in the next version:

curl -X PUT -F 'data=@/path/to/file.jpg' -F 'props={"title":"my modified title"}' http://localhost:41184/resources/:id


After you release the Release, I will test it and continue to give feedback here

I tried to update via form-data, but it doesn't seem to work, I looked at the implementation, it seems that PUT must pass data, which is wrong, maybe just modify some resource's properties, such as the resource's title @laurent

The PUT call has the same structure as the POST one - you can pass file and optionally some metadata, like resource title, etc. For me that was working fine, are you getting any error?

No, I found that it is currently mandatory to check the passed file, and you can't just update attributes such as title

error: Resource cannot be created without a file

ref: Plugins: Allow updating a resource via the data API · laurent22/joplin@37d51c3 · GitHub

At least with Joplin 2.7.13, it was possible to modify the title only. However, there might be different behaviour due to the latest changes:

# creating a resource like described in https://joplinapp.org/api/references/rest_api/#post-resources -> success
curl -F 'data=@./test/grant_authorization_button.png' -F 'props={"title":"my resource title"}' http://localhost:41184/resources?token=<YOUR_TOKEN>

# omitting the props field -> fails with HTTP 500
curl -F 'data=@./test/grant_authorization_button.png' http://localhost:41184/resources?token=<YOUR_TOKEN>

# modifying the resource title only -> succeeds
curl -X PUT -F 'props={"title":"another title"}' http://localhost:41184/resources/<RESOURCE_ID>?token=<YOUR_TOKEN>

# modifying the resource data only -> fails with HTTP 500
curl -X PUT -F 'data=@./test/another_image.png' http://localhost:41184/resources/<RESOURCE_ID>?token=<YOUR_TOKEN>

# modifying the resource data and title -> succeeds, but doesn't update the resource data
curl -X PUT -F 'data=@./test/another_image.png' -F 'props={"title":"my resource title"}' http://localhost:41184/resources/<RESOURCE_ID>?token=<YOUR_TOKEN>

It would be interesting to see whether the test fails if one of title or path is omitted: joplin/Api.test.ts at 7e8927398aeb4e834f5bc67aba6fd919531353c6 · laurent22/joplin · GitHub.

I get the following error

Also, I'm using development mode with the latest code from the master branch

Oh, indeed there's a regression then. I forgot it was possible to modify resource attributes using PUT. I'll update this to restore the previous behaviour.


Ok it's now fixed in this commit: Api: Fixed updating resource content · laurent22/joplin@f2bfa30 (github.com)


Tested and available, maybe when will the beta version be released?

I don't know, especially since the Windows app no longer builds on CI. It might be several weeks.

Found a new problem, when I use put to modify only the file content, the resource title is set to random string

curl -X PUT -F 'data=@./test/another_image.png' http://localhost:41184/resources/<RESOURCE_ID>?token=<YOUR_TOKEN>


Not sure if it's a copy-paste mistake, but your command looks like a post request. I think in this case, the random title is expected.

Sorry, I copied the wrong thing, I was referring to the mistake of using put /resources/id to modify the resource content but also reset the resource title

1 Like

Currently I fix this by calculating the filename every time I modify the content of the resource, refer to:

Ok I think we're getting there. This issue is now fixed in this commit:

So now it's possible to update the resource file content without having to set the title at the same time.

1 Like

The fix has been tested

1 Like

joplin-vscode-plugin has released 0.7.0 beta, which strongly depends on this api to implement the update of attachments