代表用户在Zendesk上创建一张工单,但不发送电子邮件。

huangapple go评论91阅读模式
英文:

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

问题

我正在使用Go语言和Zendesk API代表用户创建工单,但我不想将创建工单的邮件发送给用户。有没有办法实现这个需求?

以下是我的实现代码:

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
}
英文:

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
}

答案1

得分: 1

我终于找到了方法。

  1. 创建一个标签,并更新触发条件,以便在Zendesk仪表板上不向请求者触发任何电子邮件。
  2. 在触发时在代码中添加标签。
英文:

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.

huangapple
  • 本文由 发表于 2023年5月18日 01:38:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274807.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定