How to set ticket as spam via REST API

Freshdesk app lets you mark a ticket as spam. I want to do this via REST API.

How do I set a ticket as spam? I see in ticket properties boolean attribute ‘spam’. Is it as simple as setting this true or is there other stuff I should do like soft delete the ticket?

Oh. I just found that the documneted REST API property to mark ticket as spam is not working:

image
https://developers.freshdesk.com/api/#ticket_attributes

When I try to make following REST API call I get error as shown.

curl --location --request PUT 'https://safr-support.freshdesk.com/api/tickets/6801' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ***' \
--header 'Cookie: _x_w=41' \
--data '{
    "spam": true
}'

Response:

{
    "description": "Validation failed",
    "errors": [
        {
            "field": "spam",
            "message": "Unexpected/invalid field in request",
            "code": "invalid_field"
        }
    ]
}

How does one mark a ticket as SPAM thru REST APIs?

I looks like you’re missing ‘v2’ in your URI.

the path should be /api/v2/tickets/[id]

Good catch but that does not change the result

curl --location --request PUT 'https://safr-support.freshdesk.com/api/v2/tickets/6800' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic ****==' \
--header 'Cookie: _x_w=41' \
--data '{
    "spam": true
}'

Still results in:

{
    "description": "Validation failed",
    "errors": [
        {
            "field": "spam",
            "message": "Unexpected/invalid field in request",
            "code": "invalid_field"
        }
    ]
}

Yeah scoured the API docs (v1 & v2) and it’s not listed as an updatable field in the API.

I guess that manually setting a ticket to spam also asks to block the contact. Since it’s a compound step having it in the API would be more difficult.

Your only option to mark it as spam is using Automations.
You could create a custom field - mark that field through the API and trigger off that to mark it as spam. It’s not as elegant, but it would get you there.

Thanks. I guess this is the best answer I’m going to get so I’ll mark it as answered.

The one thing an automation does not allow is setting associated person as spam the way you can do so in the UI.

That is true, but deleting a contact will block them.
So you can do that after - soft delete then delete or force delete through the API

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.