cloudbees-oss / zendesk-java-client

A Java client library for interacting with Zendesk
https://developer.zendesk.com/rest_api/docs/api-clients/java#zendesk-java-client-by-cloudbees
Apache License 2.0
153 stars 252 forks source link

Creating a ticket with a comment that is set as public does not actually get set as public. #706

Closed billnoom closed 2 months ago

billnoom commented 4 months ago

Describe the bug When creating a ticket, if a Comment is set to public (using setPublic(true)), the comment isn't actually set to public when the ticket is created.

To Reproduce

Ticket ticket = new Ticket();
ticket.setRequester(new Ticket.Requester(createTicketRequest.getEmail(), createTicketRequest.getEmail()));
Comment comment = new Comment("My initial comment");
comment.setPublic(true);
ticket.setComment(comment);
ticket.setDescription("Some description");
ticket.setTags(getTags());
ticket.setSubject("My subject");
ticket.setTicketFormId(formId);
zenDeskInstance.getApiClient().createTicket(ticket);

The comment created with this ticket does not have the "public" attribute set to true.

Turning on "debug" logging, we can see the comment in the JSON request has "public" set to false.

  "events": [
      ...
            {
                "id": 30911026078611,
                "type": "Comment",
                "author_id": 30767222336211,
                "body": "My initial comment",
                "html_body": "<div class=\"zd-comment\" dir=\"auto\"><p dir=\"auto\">My initial comment</p></div>",
                "plain_body": "My initial comment",
                "public": false,
                "attachments": [],
                "audit_id": 30903023478483
            },
      ...
  ]

Expected behavior We would expect the comment flagged as public to be public.

It should be noted that if you first create the ticket then create a separate request to create a comment (with the comment set to public), that it actually works as expected (the comment is created with the public flag set to true).

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information): N/A

Smartphone (please complete the following information): N/A

github-actions[bot] commented 2 months ago

This issue/PR is stale because it has been opened 60 days with no activity. Remove stale label or comment or this will be closed in 7 days

PierreBtz commented 2 months ago

@billnoom sorry for the delay. I tried to reproduce with no luck:

// this works properly and opens a ticket with an initial "My initial comment" that is public
  public static void main(String[] args) {
    try(var zd = new Zendesk.Builder("**")
            .setUsername("**")
            .setToken("**")
            .build()) {
      Ticket ticket = new Ticket();
      ticket.setRequester(new Ticket.Requester("**", "**"));
      Comment comment = new Comment("My initial comment");
      comment.setPublic(true);
      ticket.setComment(comment);
      ticket.setDescription("Some description");
      ticket.setSubject("[Zendesk Java Client] Reproducer for gh-706");
      zd.createTicket(ticket);
    }
  }

I noticed reading through your sample that you are not calling directly the zendesk java client, which makes me think you have some additional logic in your wrapper that might explain the discrepancy we see.

billnoom commented 2 months ago

Thanks for taking a look! I ended up finding a work around. I think your assessment is correct; there's likely some additional logic in our wrapper that was causing an issue.

PierreBtz commented 2 months ago

Great, thanks for the feedback!