# How to add a tag to a note via the API

**URL:** <https://discourse.joplinapp.org/t/how-to-add-a-tag-to-a-note-via-the-api/14187>\
**Category:** Development\
**Created:** [22 January 2021 21:06 UTC](https://discourse.joplinapp.org/t/how-to-add-a-tag-to-a-note-via-the-api/14187 "2021-01-22T21:06:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [22 January 2021 21:06 UTC](https://discourse.joplinapp.org/t/how-to-add-a-tag-to-a-note-via-the-api/14187/1 "2021-01-22T21:06:06Z")

</div>

I am trying to use the API to add a tag to a note but facing some issues.

I'm seeing this in the console

```auto
Uncaught (in promise) Error: Missing note ID
    at Object.<anonymous> (C:\dev\joplin\packages\lib\services\rest\routes\tags.js:29)
    at Generator.next (<anonymous>)
    at fulfilled (C:\dev\joplin\packages\lib\services\rest\routes\tags.js:5)

```

But the command itself does contain the note id:

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

The [API doc](https://joplinapp.org/api/references/rest_api/#post-tags-id-notes) isn't very helpful here either

```auto
POST /tags/:id/notes

Post a note to this endpoint to add the tag to the note. The note data must at least contain an ID property (all other properties will be ignored).

```

This is how I call the API:

```auto
				await joplin.data.post(['tags', message.tag.id, 'notes'], null, {
					note: {
						id: noteId
					},
				});

```

Appreciate any advice.

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [22 January 2021 21:15 UTC](https://discourse.joplinapp.org/t/how-to-add-a-tag-to-a-note-via-the-api/14187/2 "2021-01-22T21:15:19Z")

</div>

As an aside, what's the point of using a typed language if you end up with a bunch of any's:

```javascript
post(path: Path, query?: any, body?: any, files?: any[]): Promise<any>;

```

---

<div class="post-metadata">

**Author:** ![roman\_r\_m](https://yyz2.discourse-cdn.com/flex028/user_avatar/discourse.joplinapp.org/roman_r_m/32/3297_2.png) [@roman\_r\_m](https://discourse.joplinapp.org/u/roman_r_m)\
**Post date:** [22 January 2021 22:28 UTC](https://discourse.joplinapp.org/t/how-to-add-a-tag-to-a-note-via-the-api/14187/3 "2021-01-22T22:28:24Z")

</div>

Ok, nevermind, figured this out. It should be

```auto
await joplin.data.post(['tags', message.tag.id, 'notes'], null, {
	id: noteId
});

```

Oh the joy of dynamic typing!

---

<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:** [22 January 2021 23:10 UTC](https://discourse.joplinapp.org/t/how-to-add-a-tag-to-a-note-via-the-api/14187/4 "2021-01-22T23:10:30Z")

</div>

Pull requests are welcome if you've identified things that can be improved.
