gozendeskzendesk-api

Creating a ticket on zendesk on behalf of a user, but not sending an email


I am using Go with Zendesk API to create tickets on behalf of a user, but I don't want the ticket-creating mail sent to the user. Is there any way to achieve this? Here is my implementation:

func CreateZendeskTicket(title, body, email string) error {
    ticket := ZendeskTicket{
        Ticket: Ticket{
            Comment: Comment{
                Body: body,
            },
            Priority: "normal",
            Subject:  title,
            Requester: Requester{
                Email: email,
            },
        },
    }
    payload, err := json.Marshal(ticket)
    if err != nil {
        return err
    }
    url, _ := url.JoinPath(configs.CONFIG.Zendesk.BaseURL, "api/v2/tickets.json")
    req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
    if err != nil {
        return err
    }

    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("Authorization", "Basic "+configs.CONFIG.Zendesk.APIKey)

    client := &http.Client{}
    res, err := client.Do(req)
    if err != nil {
        return err
    }
    defer res.Body.Close()
    if res.StatusCode != 201 {
        return errors.New("Failed to create ticket: " + res.Status)
    }
    return nil
}

Solution

  • I finally found the way to do it.

    1. Create a tag and update the trigger condition so that it does not trigger any email to the requester on Zendesk dashboard
    2. Add the tag on the code when triggering.