Calling Ticket API from script.js within Zendesk Help Centre - CORS issue



投稿日時:2023年9月22日

I am attempting to call the v2/tickets.json API endpoint from within the scripts.js file in the help centre theme.  Both the help centre and API are presumably within the Zendesk environment - so I am using basic auth (rather than OAuth).

However, I receive the following error:

Access to XMLHttpRequest at 'https://XXX.zendesk.com/api/v2/tickets.json' from origin 'https://help.XXX.co.uk' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

In a sandbox environment, I am able to call the sandbox tickets API fine passing basic auth (email and API token).  Also, calling the live API from Postman works fine.

My code:

$.ajax({
    url: 'https://XXX.zendesk.com/api/v2/tickets.json',
    type: 'post',
    data: JSON.stringify({ticket: postData}),
    headers: {
      "Content-Type": "application/json",
      "Authorization": "Basic " + btoa('EMAILADDRESS/token' + ":" + 'APITOKEN')
    },
    dataType: 'json',
    success: function (data) {
      console.info(data);
    },
    error: function (xhr, status, error) {
      console.info(error);
    }
});

Thanks in advance


0

3

0件のコメント

サインインしてコメントを残してください。

お探しのものが見つかりませんか?

新規投稿