Create Trigger via API

Hi,

I’m using the Zammad Cloud Environment (not self hosted) and try to create a Trigger via API.
I want to create a trigger with the Name “Testgroup”, a condition “ticket.group = Testgroup” and the trigger should perform “ticket.service=Testgroup”.

ticket.service is a hidden custom textfield (50).

I use Powershell:

$headers = @{
    'authorization'='Bearer <MyToken>'
    'ContentType' = 'application/json'
}
$CType = 'application/json; charset=utf-8'
$BaseURI = 'https://<MyDomain>.zammad.com/api/v1/'
Invoke-RestMethod -Uri $BaseURI'triggers' -Method POST -Headers $headers -ContentType $CType -Body '{"name":"SetService - Testgroup","active":"true","condition":["ticket.group_id=9"],"perform":["ticket.service=Testgroup"]}'

The response is “422 Unprocessable Entity”
Creation from users and groups work like a charm.

What I’m doing wrong?

Thanks in advance for your help.

Now i tried to reach my goal via Postman and changed the api Request to

{"name":"SetService - Testgruppe","active":true,"condition":{"ticket.group_id":{"operator":"is","value":"9"}},"perform":{"ticket.service":{"value":"Testgruppe"}}}

Now I get a more detailled response: “error”: “Name can’t be blank”

As you can see my name is not blank.

I found my mistake and could solve it.
In Postman I missed to Format the Body as JSON.
grafik

In Powershell it was a misformated JSON-String. The following one worked:

$headers = @{
    'authorization'='Bearer <MyToken>'
    'ContentType' = 'application/json'
}
$CType = 'application/json; charset=utf-8'
$BaseURI = 'https://<MyDomain>.zammad.com/api/v1/'
Invoke-RestMethod -Uri $BaseURI'triggers' -Method POST -Headers $headers -ContentType $CType -Body '{"name": "SetService - Testgroup","condition": {"ticket.group_id": {"operator": "is","value": "9"}},"perform": {"ticket.service": {"value": "Testgroup"}},"disable_notification": true,"active": true}'

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