# Feat: can resource api support put function?

**URL:** https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690
**Category:** Features
**Created:** [26 March 2022 07:55 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690 "2022-03-26T07:55:02Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [26 March 2022 07:55 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/1 "2022-03-26T07:55:02Z")

</div>

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

@laurent

---

<div class="post-metadata">

### Author: ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)
#### Post date: [28 March 2022 15:49 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/2 "2022-03-28T15:49:29Z")

</div>

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

> <https://github.com/laurent22/joplin/commit/37d51c3b587160efb8c492133d4d0b8566a339e6>

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

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [3 April 2022 10:09 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/3 "2022-04-03T10:09:31Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [8 April 2022 02:01 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/4 "2022-04-08T02:01:05Z")

</div>

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

> <https://github.com/laurent22/joplin/commit/37d51c3b587160efb8c492133d4d0b8566a339e6#diff-519649c8c26b2c0e5874ab579f1122e9c095ea83ae904421ff3195d7f68df58cR53>

---

<div class="post-metadata">

### Author: ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)
#### Post date: [8 April 2022 09:18 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/5 "2022-04-08T09:18:45Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [8 April 2022 09:44 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/6 "2022-04-08T09:44:40Z")

</div>

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](https://github.com/laurent22/joplin/commit/37d51c3b587160efb8c492133d4d0b8566a339e6#r70801135)

---

<div class="post-metadata">

### Author: ![Marph](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/marph/32/10800_2.png) [@Marph](https://discourse.joplinapp.org/u/Marph)
#### Post date: [8 April 2022 11:06 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/7 "2022-04-08T11:06:23Z")

</div>

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:

```bash
# 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/packages/lib/services/rest/Api.test.ts at 7e8927398aeb4e834f5bc67aba6fd919531353c6 · laurent22/joplin · GitHub](https://github.com/laurent22/joplin/blob/7e8927398aeb4e834f5bc67aba6fd919531353c6/packages/lib/services/rest/Api.test.ts#L361-L367).

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [8 April 2022 11:23 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/8 "2022-04-08T11:23:02Z")

</div>

I get the following error

 ![image](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/2X/d/d98749a8aa6f88a0dae6aa0869eb3f79acab7f74.png)

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

---

<div class="post-metadata">

### Author: ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)
#### Post date: [8 April 2022 11:27 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/9 "2022-04-08T11:27:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)
#### Post date: [9 April 2022 10:59 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/10 "2022-04-09T10:59:08Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [10 April 2022 06:00 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/11 "2022-04-10T06:00:07Z")

</div>

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

---

<div class="post-metadata">

### Author: ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)
#### Post date: [10 April 2022 09:22 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/12 "2022-04-10T09:22:06Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [10 April 2022 10:58 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/13 "2022-04-10T10:58:26Z")

</div>

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/](http://localhost:41184/resources/)\<RESOURCE\_ID\>?token=\<YOUR\_TOKEN\>

![image](https://canada1.discourse-cdn.com/flex028/uploads/cozic/original/2X/a/a87276c8b44cb8a3c4de277393530e00f5524d1d.png)

---

<div class="post-metadata">

### Author: ![Marph](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/marph/32/10800_2.png) [@Marph](https://discourse.joplinapp.org/u/Marph)
#### Post date: [10 April 2022 11:04 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/14 "2022-04-10T11:04:06Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [10 April 2022 11:05 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/15 "2022-04-10T11:05:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [10 April 2022 11:08 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/16 "2022-04-10T11:08:39Z")

</div>

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

> <https://github.com/rxliuli/joplin-utils/commit/e97ee75eb749ab075d101e96ca2e20f901dfadff#diff-1da71608ed988961835f364b78b6ea1f0240f95332632318884e2439a86898f5R82>

---

<div class="post-metadata">

### Author: ![laurent](https://avatars.discourse-cdn.com/v4/letter/l/ce7236/32.png) [@laurent](https://discourse.joplinapp.org/u/laurent)
#### Post date: [11 April 2022 16:02 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/17 "2022-04-11T16:02:28Z")

</div>

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

> <https://github.com/laurent22/joplin/commit/74273cd570fec760bbeaeeca08b5def1ed93e038>

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

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [12 April 2022 04:39 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/18 "2022-04-12T04:39:45Z")

</div>

The fix has been tested

> <https://github.com/rxliuli/joplin-utils/commit/a123aad553f28b2537da8d1704d3001b4ca80651#diff-2d76758ee0440e32112953118d79de8e738a03f1a69f17b703391a7ebdc92d62R74>

---

<div class="post-metadata">

### Author: ![rxliuli](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/rxliuli/32/4083_2.png) [@rxliuli](https://discourse.joplinapp.org/u/rxliuli)
#### Post date: [14 April 2022 15:17 UTC](https://discourse.joplinapp.org/t/feat-can-resource-api-support-put-function/24690/19 "2022-04-14T15:17:04Z")

</div>

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

> [@Joplin-vscode-plugin roadmap](https://discourse.joplinapp.org/t/joplin-vscode-plugin-roadmap/11335/29):
>
> Release 0.7.0 [https://github.com/rxliuli/joplin-utils/releases/tag/joplin-vscode-plugin%400.7.0](https://github.com/rxliuli/joplin-utils/releases/tag/joplin-vscode-plugin%400.7.0) Major update Supports vscode integration entirely through the joplin clipper api, which solves many existing issues including Support joplin cli as backend, ref: [https://discourse.joplinapp.org/t/16735](https://discourse.joplinapp.org/t/16735) Support joplin flatpak application, ref: [https://github.com/rxliuli/joplin-utils/issues/28](https://github.com/rxliuli/joplin-utils/issues/28) Support remote installed joplin as backend (not tested), ref: [https://github.com/rxliuli/joplin-utils/issu…](https://github.com/rxliuli/joplin-utils/issues/35)
