1

BY THIS CODE PLEAS HELP HOW TO CREATE ZENDESK TICKET

<script type = "text/javascript" >
  $(function() {
    $("#btnGet").click(function() {
      $.ajax({
        url: 'https://xxxx.zendesk.com/api/v2/tickets/1.json',
        contentType: 'application/json',
        type: 'POST',
        data: JSON.stringify({
          "ticket": {
            "subject": "Tst SUB",
            "comment": {
              "body": "Test BODY"
            }
          }
        }),
        success: function(response) {
          alert("Hello: Success");
        },
        failure: function(response) {
          alert("Fail");
        },
        error: function(response) {
          alert("Error");
        }
      });
    });
  });
</script>
technophyle
  • 7,972
  • 6
  • 29
  • 50
  • URL is wrong , you are adding a .json in url , please find the right URL and pass it with proper data required in data element. For making a HTTP call , we need Http method , url , input data. – HulkSapien Feb 09 '20 at 16:07
  • 1
    What happens when this does fail? Error messages, anything in the console, etc. Try printing the response in the failure and error responses. (That might have to be fail, not failure) – Nate Feb 09 '20 at 16:23

2 Answers2

0

It appears that you have some issues with the body section.

"comment": { "body": :Test BODY" }

try

"comment": { "body": "Test BODY" }
Mech
  • 3,952
  • 2
  • 14
  • 25
0

Your code works, the only mistake is in the request url. When creating a new ticket you don't need to add any ticket number.

Just edit the url removing 1.json and leave 'https://xxxx.zendesk.com/api/v2/tickets'

Also, if you're not sending the request from within Zendesk (e.g. a custom app) you need to authenticate the request.

Ingirorhaun
  • 381
  • 4
  • 6