happyfoxinc / helpstack

iOS Support Framework
http://helpstack.io
MIT License
477 stars 69 forks source link

Zendesk integration does not work #15

Open KrauseFx opened 9 years ago

KrauseFx commented 9 years ago

I used the following code:

HSZenDeskGear *zenDeskGear  = [[HSZenDeskGear alloc]
                               initWithInstanceUrl : @"https://sunapps.zendesk.com"
                               staffEmailAddress   : @"test@email.com"
                               apiToken            : @"[mySecretToken]"
                               localArticlePath    : @""];

HSHelpStack *helpStack = [HSHelpStack instance];
helpStack.gear = zenDeskGear;

When submitting a new issue I get a 401 error:

HelpApp:- Create new ticket failed: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: unauthorized (401)" UserInfo=0x156ab520 {NSErrorFailingURLKey=https://sunapps.zendesk.com/api/v2/tickets.json, com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x102760b0> { URL: https://sunapps.zendesk.com/api/v2/tickets.json } { status code: 401, headers {
    "Cache-Control" = "no-cache";
    Connection = "keep-alive";
    "Content-Length" = 37;
    "Content-Type" = "application/json; charset=UTF-8";
    Date = "Mon, 25 Aug 2014 17:05:02 GMT";
    Server = nginx;
    "Set-Cookie" = "_zendesk_shared_session=eyJpZCI6IjI5MmFlNWRiMzliMGUwOGVlOGZlNDJlZWE4NzhkZmRmIn0%3D--69246609b32f73315128a33da4afe5aa76323860; path=/; secure; HttpOnly";
    Status = "401 Unauthorized";
    "Www-Authenticate" = "Basic realm=\"Web Password\"";
    "X-Rack-Cache" = "invalidate, pass";
    "X-Request-Id" = 3ab5119486bb25f9872c95c4e485c2c7;
    "X-Runtime" = "0.054623";
    "X-UA-Compatible" = "IE=Edge,chrome=1";
    "X-Zendesk-Origin-Server" = "app37.pod1.ord.zdsys.com";
    "X-Zendesk-Request-Id" = 78581b9e2687bdbe3733;
} }, NSLocalizedDescription=Request failed: unauthorized (401)}

Manually sending the request works just fine:

curl -u felix@sunapps.net/token:[mySecretToken] https://sunapps.zendesk.com/api/v2/tickets.json
nalinchhajer1 commented 9 years ago

Hi, I have tested this by my account and also in new zendesk account, and it works in both the cases. I don't see any typo in your call also. May be the secret key you generated is a problem. Are you using the secret key generated in Settings -> API section of zendesk.

There is one more thing, don't forget to press save when you have enabled API for zendesk. I did multiple time and ran into same issue as yours, UI shows API secret is generated but unless you press save button it does not reflect in server. There seems to be some usability issue there.

Try again and let me know, and also check your staff email address also.

KrauseFx commented 9 years ago

Hi, thanks for your reply. I did click save and it was in the right session. I'll keep trying the next few days. Good to know it's related to my account

grabbou commented 9 years ago

Sounds like this error has not been fixed yet unfortunately. Getting 401 unauthorised all the time. Wish it works flawlessly as ZenDesk official SDK is totally bugged.

anirudh24seven commented 9 years ago

@grabbou: We'll find out what the issue might be due to, and get back to you.

anirudh24seven commented 9 years ago

@grabbou: I just tried creating a new ticket and it worked fine.

Can you check if the following actions are done properly:

  1. After you enable Token Access, please click the Save button.
  2. If you are copy-pasting the token, ensure you aren't copying more characters than necessary. For example, if you are copying from the Zendesk web interface, you might be accidentally copying the accompanying text that says, "Last used less than 60 minutes ago".
  3. Try the same request manually using cURL.

If you were doing all of the above properly but still not getting it via HelpStack, you have 2 options:

  1. You could share your ZenDesk URL and a throwaway API token so that we can debug the issue for you. (You could mail us at support@happyfox.com with your details, in case you want it to be private)
  2. You can download the HelpStack source code and debug the issue inside /HelpStack/Stacks/HSZenDeskGear.m -createNewZendeskTicket:forUser:success:failure: method.