Using Zendesk webhook endpoint, getting 401 unauthorized errors

Andrew Goetz October 30, 2024

I know there have been some recent fixes/improvements with the Opsgenie and Zendesk integration. However, when I am using zendesk to create a webhook with the process and endpoint URL from the Opsgenie support documents, I still hit 401 errors.

The API key I am using is tied to an API integration I made for my team, which I think should work, so I am confused on how I would hit an unauthorized error with the Opsgenine endpoint and an opsgenie api key.

Does this require some kind of higher level Zendesk app installed into Opsgenie or Zendesk, or should only using api keys and endpoint URLs.

 

https://community.atlassian.com/t5/Opsgenie-questions/New-webhook-integration-from-Zendesk/qaq-p/2810743

https://support.atlassian.com/opsgenie/docs/integrate-opsgenie-with-zendesk/

https://jira.atlassian.com/browse/OPSGENIE-1972

https://api.opsgenie.com/v2/json/integrations/zendeskv2?apiKey=<inserting my key here>

1 answer

0 votes
Eric Sibomana
Contributor
October 31, 2024

Hello Andrew,

I understand this can be frustrating, regarding the 401 unauthorized error you're experiencing when setting up a webhook from Zendesk to Opsgenie. especially given the recent updates to the integration. 

Please verify a few key points:

  1. API Key: Confirm that you're using a valid API key generated from a global API integration in Opsgenie. This key should have the necessary permissions to create and manage alerts.
  2. Endpoint URL: Ensure you're using the correct endpoint URL for your Opsgenie domain (US or EU).
  3. Zendesk Webhook Configuration: Double-check that you've set up the webhook in Zendesk correctly, including the method (POST) and the payload format.
  4. Opsgenie Plan: Verify that your Opsgenie plan supports the Zendesk integration. The integration is available with Standard and Enterprise plans in Opsgenie, and Premium and Enterprise plans in Jira Service Management.

To troubleshoot this issue, I recommend the following steps:

  1. Generate a new API key in Opsgenie and try using it in your webhook configuration.
  2. Verify that your Opsgenie account has the necessary permissions to receive webhooks from external sources.
  3. Try setting up a simple test webhook to a service like webhook.site to ensure Zendesk is correctly sending the webhook payload.
  4. Check your Opsgenie logs for any error messages related to incoming webhooks or API requests.
  5. If possible, try setting up the integration using the Opsgenie app in the Zendesk marketplace to see if it resolves the issue.

If you've tried these steps and are still encountering the 401 error, it would be helpful to know:

  • The exact error message you're receiving
  • The Opsgenie and Zendesk plans you're currently using
  • Any recent changes to your Opsgenie or Zendesk configurations

Please provide this additional information, and we'll be able to assist you further in resolving this issue.

Don't hesitate to reach out if you need any clarification or have additional questions. 

Best regards,
Eric

Andrew Goetz December 2, 2024

Hi Eric,

Thanks for the answer. Lost track of this for a while, but I am still struggling to get it to work.

I have created a new Opsgeine API, and used that key successfully with the https://api.opsgenie.com/v2/alerts endpoint. This is working as expected when I call things from my terminal via `curl` (creates the Opsgenine alert tied to the team which owns the API key).

However, when I try and do this via a Zendesk webhook, I run into trouble and keep hitting 401 Unauthorized errors.

I think this is due to me being unable to use the https://api.opsgenie.com/v2/alerts endpoint with the zendesk webhook functionality, and instead I am using the endpoint from the docs and instructions here:
https://community.atlassian.com/t5/Opsgenie-questions/New-webhook-integration-from-Zendesk/qaq-p/2810743

The https://api.opsgenie.com/v2/json/integrations/zendeskv2?apiKey=<your-api-key> endpoint doesnt seem to work, which may be due to the lack of the headers or some other kind of authorization method.

The result is similar to the one below:{"took":0.013,"requestId":"91e42f85-2984-4472-a8d9-ca8125d341b8","code":2,"error":"HttpClientErrorException[401 Unauthorized]"}


I have yet to try installing the Opsgenie integration in Zendesk, as I think this is a pretty simple task (when new ticket is created in zendesk, create an alert in Opsgenie) that doesnt need all the other features of this integration. if you think that is the next best thing to try, please let me know.

Andrew Goetz December 3, 2024

@Eric Sibomana and others who find this in the future, I have finally figured it out.

When you google "Zendesk and Opsgenie integration" you will find the docs I linked in my first post, all of which mention a Zendesk webhook with Authorization set to None and using a Form Encoded payload and the endpoint listed below:

https://api.opsgenie.com/v2/json/integrations/zendeskv2?apiKey=<your-api-key> 

 

This may work for the Zendesk and Opsgenie two way sync (not sure, havent tired it), but if your use case is basic to have a new Zendesk ticket create an alert in Opsgenie, you actually want to avoid these docs altogether as they are not helpful for you.

 

If you want to create a new Alert in Opsgenie for a Zendesk trigger, you can simply do the following:

In Opsgenie, use the Integrations tab to create a new API integration, and set it to global or to your Team, whichever you prefer. The API key format should look something like: 1340x113-0uu6-4ca7-a111-43241dbe08xt

Then once you have that Opsgenie API key, you can use it in a Zendesk webhook for the basic Opsgenie alert api endpoint (and not this zendeskv2 endpoint that the Opsgenie documentation points you to).

Zendesk webhook should look like:
Endpoint URL: https://api.opsgenie.com/v2/alerts

Request method: POST

Request format: JSON

Authentication: API key

Header name: Authorization

Value: GenieKey 1340x113-0uu6-4ca7-a111-43241dbe08xt

(note, sub your actual Opsgenine API key for this sample one)

Then you can send a JSON payload to test the webhook like the one below:

{"message": "Zendesk Opsgenie Testing","alias": "Zendesk Testing","description":"Zendesk Opsgenie tests"}'

Just use the Zendesk "Test Webhook" feature with this payload to make sure it works, and if you get a 202 response code, you set it up correctly and should have the alert created as you expect.

You can then use this webhook in your Zendesk triggers via the Notify by... functionality to send whatever payload you need based on the parameters in the Opsgenie documentation. 

 

TL;DR - Ignore the Opsgenine Zendesk related docs if you have just a basic use case and simple use the regular Opsgenie alert API endpoint

 

I hope this saves other folks some time.

Thanks again for your help and advice.

Eric Sibomana
Contributor
December 4, 2024

Hello Andrew,

Thank you for sharing your solution and insights regarding the integration of Zendesk with Opsgenie. It's great to hear that you've found a working method for your use case, and your detailed explanation will certainly help others facing similar challenges.

To summarize your approach for anyone else looking to achieve the same functionality:

 

API Integration Setup: Create a new API integration in Opsgenie and ensure it is set to either global or specific to your team. This will generate an API key that you can use.

 

Webhook Configuration in Zendesk:

  • Endpoint URL: Use `https://api.opsgenie.com/v2/alerts`.
  • Request Method: Set this to POST.
  • Request Format: Choose JSON.
  • Authentication: Use the API key with the header:
  • Header Name: `Authorization`
  • Value: `GenieKey <your-actual-api-key>` (replace with your generated API key).

 

Testing the Webhook: You can test the webhook using a sample JSON payload like:

   ```json

   {

     "message": "Zendesk Opsgenie Testing",

     "alias": "Zendesk Testing",

     "description": "Zendesk Opsgenie tests"

   }

   ```

   When you use the "Test Webhook" feature in Zendesk, a successful response (202) indicates that the alert has been created correctly in Opsgenie.

 

Using Webhook in Triggers: Integrate this webhook into your Zendesk triggers using the Notify by... functionality to automate alert creation based on ticket events.

 

Your conclusion to bypass the specific Zendesk-related documentation for simpler use cases is valuable advice. This streamlined approach should save time and reduce complexity for users who only need basic alert functionality.

 

Best regards,

Eric

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
TAGS
AUG Leaders

Atlassian Community Events