Anonymous Request Posted via the API | Community
Skip to main content

Anonymous Request Posted via the API

  • December 10, 2018
  • 10 replies
  • 0 views

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!

This topic has been closed for replies.

10 replies

  • December 10, 2018

Hi Josiah-

Are you trying this in an incognito browser? Using only the 2nd ajax request I was able to create a ticket.

 


  • Author
  • December 11, 2018

Hey Joey, thanks for the response. I'm not using an incognito window, should I be? If it works for you, my hunch then would be that it's my site settings? Every single time I get an invalid authenticity error. I've removed the first piece...

$.ajaxSetup(...);

However, that still doesn't seem to work. I did check that I've enabled anyone to submit tickets and disabled asking users to register. Our site currently isn't "live" given that we're in the midst of setting it all up, but I was hoping there would be a way to test this prior to going live. Anything else I can try or check?

Thanks!


  • December 11, 2018

Hey Josiah-

Are you saying it isn't working for you even in incognito? The only time I was able to recreate an auth error was in the scenario in which I had user credentials already stored in a browser session.

Joey 


  • Author
  • December 11, 2018

Ok, well that's good to know. Our site hasn't been activated yet, so I need to login to view it. I'm assuming that's the issue then?

So, if you're telling me that you cannot be logged in at all to send this request that's fair, I just wasn't aware of that restriction. If that's true, my next question is, how do I test this out before the site is activated so I can be sure it will work once it is live?


  • December 12, 2018

It looks like requester is misspelled (requestor in your code example).


  • Author
  • December 12, 2018

Thanks and good catch, but it still doesn't work for me.


  • December 12, 2018

Thanks for pointing that out, Vincent. I had noticed that, but in light of the error presented it didn't make sense (I would expect a 422). I appreciate you bringing it up, and plan on investigating some more into requester/requestor.

@Josiah- depending on your plan type, you may be able to take advantage of our Sandbox feature (Enterprise only). Otherwise, even were you to activate Guide, it could always be deactivated and then again reactivated.
Another alternative would be to restrict any and all content to 'Internal Only,' allowing an end-user/anon-user to still navigate to your Guide instance and submit a request. If I think of anything else I'll post it here, unless Vincent has any ideas.


  • Author
  • December 12, 2018

So you're saying this would work on the sandbox? Ideally all I want to do is submit an anonymous request via the API given the code above. I know you said that my code worked for you, but it doesn't on my current site. Can you please tell me what I need to check and verify so this will work? Thanks!


  • December 12, 2018

I am Josiah, yes. Given the unique URL schema, and presuming the sandbox wouldn't be linked to from any external resource, you could test simply by activating Guide, visiting the HC in incognito mode, and running that in the console. Once testing is complete, Guide could then be deactivated once again from the admin panel.


  • Author
  • December 12, 2018

Ok, thanks. I'll give it a shot.