How to use REST API to set tag in a document (task)?

Using the REST API I can create, update and remove documents. But how do I set a document’s tag using Rest Api? Already tried to do it sending this Json in the create method (I’m trying to add a tag to a task):

{
	"subject": "Set a tag from API",
	"tag": "Service Request"
}

And this one in the update method:

{
	"tag": "Service Request"
}

Hi Rodrigo, try this:

Endpoint: /api/method/frappe.desk.tags.add_tag
Method: POST
Params:

  • dt (target DocType)
  • dn (target name)
  • tag (tag to attach)

Example: Attach “My Tag” to Sales Invoice SINV-0001

curl -X POST \
https://my.erpnext.com/api/method/frappe.desk.tags.add_tag?tag=My Tag&dt=Sales Invoice&dn=SINV-0001 \
-H "Authorization: Basic tZaxXzUdgCXWhokGmoFNUJDfzpfmFwmbtgebyNRMm=="

It worked perfectly. Thank you!

Hello. This does not seems to work anymore. Can anyone please confirm?
We want to do exactly this but the endpoint does not work anymore. Do we have a new endpoint that we can use?

Thanks

Hi @Karamveer_Singh, looks like the method was moved to a different location. This should work in Version 13:

curl -X POST \
    https://my.erpnext.com/api/method/frappe.desk.doctype.tag.tag.add_tag?tag=My Tag&dt=Sales Invoice&dn=SINV-0001 \
    -H "Authorization: Basic tZaxXzUdgCXWhokGmoFNUJDfzpfmFwmbtgebyNRMm=="

Hi @rmeyer. Couldn’t thank you enough. It worked perfectly. Thanks!
Just a quick question, how did you find that this was moved to a different location? Just for my knowledge so I trouble you guys less next time :slight_smile:

You’re welcome.

I opened my browser’s developer console and checked what API calls are made when I add a tag manually in ERPNext.