Forum Discussion

jeffshurtliff's avatar
5 years ago

Add multiple tags to a message with a single API call?

Can anyone tell me if it is possible to add multiple tags to a message with a single API call, or if they have to be added one-by-one with a separate API call for each? Looking at the v2 subcollecti...
  • AdamN's avatar
    5 years ago

    Hi jeffshurtliff ,

    It looks like when trying to update via the subcollection, you can only add one tag at a time. However, through the message collection itself, you can set multiple tags at a time.

    For example:

    curl --location --request PUT '.../api/2.0/messages/882?restapi.session_key=...' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "data":{
            "type":"message",
            "tags": [
            	{
                	"type": "tag",
                	"text": "tag3"
            	},
            	{
                	"type": "tag",
                	"text": "tag4"
            	}
            ]
        }
    }'

    Please be aware that this will set the tags exactly as you've specified, and any existing tags on the post that are not specified will be removed. So if the message in my example started with tags "tag1", "tag2", and "tag3", after the call it would have only tags "tag3" and "tag4". Tags "tag1" and "tag2" would be deleted.

    I hope this helps!