I've seen this same issue from a couple posts in the community already, but I can't seem to get my code working. I've tried posting an anonymous ticket from the help center via this code...
$.ajaxSetup({
beforeSend: function(xhr, settings) { xhr.setRequestHeader('X-CSRFToken', TOKEN); }
});
$.ajax({
url: 'https://SUBDOMAIN.zendesk.com/api/v2/requests.json',
type: 'POST',
data: { "request": { "requester": { "name": "Anonymous Customer" }, "subject": "Test Request", "comment": { "body": "This is just a test." } } },
success: function (response) { console.log('success', response); },
error: function (error) { console.log('error', error); }
});
I've used this article as a reference (https://developer.zendesk.com/rest_api/docs/support/requests#create-request). I've checked and the settings listed in that article are off, but I still always get an invalid authenticity token error.
Any help is appreciated, thanks!
Hi Josiah-
Are you trying this in an incognito browser? Using only the 2nd ajax request I was able to create a ticket.