javascriptzendeskzendesk-app

Retrieving URL parameters from Zendesk app


I want to generate a link in my "CRM" (legacy custom CRM with little options) that will allow a user to access a specific Zendesk profile. The thing is that in the CRM I don't have access to the user ID in Zendesk, and I only have the email and an internal ID (which is the external ID of the Zendesk user).

In order to do this, I wanted to:

I have the app working but have one issue: I can't retrieve the URL params. These are my results:

window.location.href

Result: https://[appID].apps.zdusercontent.com/[appID]/assets/[some ID]/iframe.html?origin=https%3A%2F%2F[my ZD domain].zendesk.com&app_guid=[another ID]

This is not showing the url parameters but the url where the app is hosted

window.top.location.href

Result: No 'Access-Control-Allow-Origin' header is present on the requested resource So a Zendesk CORS error

document.referrer

Result: https://[my ZD domain].zendesk.com/ But no parameters

document.location.ancestorOrigins[0]

Result: https://[my ZD domain].zendesk.com Also no parameters

None of these results provide the parameters in the url and I can't think of other ways to extract them.

So my questions are:

Thank you everyone for your help and have a nice day.


Solution

  • You won't be able to access the parent url from an iframe if they are not in the same subdomain. However, depending on your app location, you might be able to access the url parameters using client.context() https://developer.zendesk.com/api-reference/apps/apps-core-api/client_api/#clientcontext

    I was able to get them from a custom app running on the nav bar, but not from one running on the top bar.

    Otherwise, you can also generate search links (your second option) like this:

    https://yoursubdomain.zendesk.com/agent/search/1?type=user&q=yoursearchquery