nukosuke / go-zendesk

Zendesk API client library for Go
https://pkg.go.dev/github.com/nukosuke/go-zendesk/zendesk
MIT License
62 stars 81 forks source link

CreateTicketComment wrong return value #269

Open enumag opened 1 year ago

enumag commented 1 year ago

The CreateTicketComment method is trying to load the response from Zendesk back into the TicketComment struct. However the response of the endpoint had a completely different structure which I'm sharing below.

This means that the returned struct is always a zero-value and doesn't contain the data of the newly created comment.

The data of the comment are in the struct under audit.events[0].

{
  "ticket": {
    "url": "https://<redacted>.zendesk.com/api/v2/tickets/2.json",
    "id": 2,
    "external_id": null,
    "via": {
      "channel": "email",
      "source": {
        "from": {
          "address": "enumag@gmail.com",
          "name": "Enumag"
        },
        "to": {
          "name": "<redacted>",
          "address": "<redacted>"
        },
        "rel": null
      }
    },
    "created_at": "2023-03-02T12:02:32Z",
    "updated_at": "2023-03-08T14:37:57Z",
    "type": null,
    "subject": "testing ticket",
    "raw_subject": "testing ticket",
    "description": "new testing ticket",
    "priority": null,
    "status": "new",
    "recipient": "<redacted>",
    "requester_id": 13408217713553,
    "submitter_id": 13408217713553,
    "assignee_id": null,
    "organization_id": null,
    "group_id": null,
    "collaborator_ids": [],
    "follower_ids": [],
    "email_cc_ids": [],
    "forum_topic_id": null,
    "problem_id": null,
    "has_incidents": false,
    "is_public": true,
    "due_at": null,
    "tags": [],
    "custom_fields": [
      {
        "id": 13571382524561,
        "value": null
      },
      {
        "id": 13571427625617,
        "value": null
      },
      {
        "id": 13571382547345,
        "value": null
      }
    ],
    "satisfaction_rating": null,
    "sharing_agreement_ids": [],
    "custom_status_id": 12333265000209,
    "fields": [
      {
        "id": 13571382524561,
        "value": null
      },
      {
        "id": 13571427625617,
        "value": null
      },
      {
        "id": 13571382547345,
        "value": null
      }
    ],
    "followup_ids": [],
    "ticket_form_id": 12333269809169,
    "brand_id": 12333264969745,
    "allow_channelback": false,
    "allow_attachments": true,
    "from_messaging_channel": false
  },
  "audit": {
    "id": 13577164093841,
    "ticket_id": 2,
    "created_at": "2023-03-08T14:37:57Z",
    "author_id": 12333884012433,
    "metadata": {
      "system": {
        "client": "Apache-HttpClient/4.5.13 (Java/17.0.5)",
        "ip_address": "<redacted>",
        "location": "<redacted>",
        "latitude": 0,
        "longitude": 0
      },
      "custom": {}
    },
    "events": [
      {
        "id": 13577135544337,
        "type": "Comment",
        "author_id": 12333884012433,
        "body": "Lorem Ipsum Dolor Sit Amet",
        "html_body": "<div class=\"zd-comment\" dir=\"auto\"><p dir=\"auto\">Lorem Ipsum Dolor Sit Amet</p></div>",
        "plain_body": "Lorem Ipsum Dolor Sit Amet",
        "public": true,
        "attachments": [],
        "audit_id": 13577164093841
      },
      {
        "id": 13577135545105,
        "type": "WebhookEvent",
        "via": {
          "channel": "rule",
          "source": {
            "from": {
              "deleted": false,
              "title": "Spaceflow Add Comment Webhook",
              "id": 13571419878673,
              "revision_id": 6
            },
            "rel": "trigger"
          }
        }
      },
      {
        "id": 13577164095633,
        "type": "Notification",
        "via": {
          "channel": "rule",
          "source": {
            "from": {
              "deleted": false,
              "title": "Notify requester and CCs of comment update",
              "id": 12333296041361,
              "revision_id": 1
            },
            "rel": "trigger"
          }
        },
        "subject": "[{{ticket.account}}] Re: {{ticket.title}}",
        "body": "{{ticket.latest_comment_html}}",
        "recipients": [
          13408217713553
        ]
      }
    ],
    "via": {
      "channel": "api",
      "source": {
        "from": {},
        "to": {
          "name": "Enumag",
          "address": "enumag@gmail.com"
        },
        "rel": null
      }
    }
  }
}