Troubleshoot device connectivity in Zendesk Support
Create a Zendesk Support app in JavaScript to help your team troubleshoot customer device connectivity issues using the emnify REST API. This app enables your team to:
- View device and SIM details (including statuses)
- View the device’s connectivity status
- Refresh device statuses
- Reset device connectivity
Prerequisites
Accounts and permissions
- A Zendesk account on a Support Professional plan or higher. You also need to be an Administrator or Account owner.
- An emnify account with at least one device and assigned SIM.
- A valid application token from your emnify Workspace, created via the emnify Portal or the emnify REST API.
Only Administrators can create application tokens in the emnify Portal. See Roles and permissions for more information.
Tools and software
- Basic JavaScript knowledge
All the necessary code is provided, but understanding JavaScript helps you customize the app.
- Node.js 14.17.3 or later installed.
- A web browser, such as Chrome or Firefox, that supports mixed HTTP and HTTPS content.
This is required to run the app locally.
Safari doesn’t support mixed content and cannot run Zendesk apps locally.
Additionally, create a custom field for your SIM identifier in Zendesk Support as outlined in the next section.
Create a custom ticket field for your SIM identifier
This app relies on a unique SIM identifier to retrieve data from the emnify REST API. Create a custom field in Zendesk Support to store and manage this identifier. Your team should be familiar with this field and use it regularly. This identifier must be:
- Usable for filtering in the List Endpoints API.
- Unique enough that it responds with a single device.
Devices are referred to as “endpoints” in the emnify REST API.
For example, you can use:
- eUICC Identifier (EID)
- Integrated Circuit Card Identifier (ICCID) with or without the final Luhn checksum digit
- International Mobile Equipment Identity (IMEI)
- A serial number or custom identifier that maps to the device name in emnify
The emnify Portal doesn’t allows for duplicate device names. If you choose this option, you need to ensure that the device name is unique and follows a consistent format. For example,
device-12345,D12345,12345, etc.
This guide uses the ICCID without the final Luhn checksum digit.
Here are the steps to create a custom field in Zendesk Support:
Follow the Zendesk Help guide to add a new custom ticket field named ICCID. Select Number (without decimals) as the field type.
Add a Display name to clarify the field’s purpose for your team.
Optionally, add a Description for admins to provide more context. If the field is visible to customers, you can include a separate description for them.
Example description for ICCID:
Complete the configuration and save the custom field by following the Adding custom ticket fields to your tickets and forms Zendesk guide.
After saving, the field appears in the Admin Center under Objects and rules > Tickets > Fields.
Note down the Field ID for the custom field. You need this ID to fetch the ICCID value.
Create a new Zendesk app
The Zendesk Apps Framework (ZAF) allows you to customize and extend your agent’s interface. For more information, see Apps in the Zendesk developer documentation.
Generate the starter files
Follow these steps to set up a new Zendesk app:
Create the app files. Use the following values when prompted:
- Directory: emnify-support-app
- Author’s name: Your name
- Author’s email: Your email address
- Author’s website: Leave blank and press Enter
- App name: emnify Support App
After completing this step, the Zendesk Command Line Interface (ZCLI) generates starter files in the emnify-support-app folder.
Run the app locally to test it in your Zendesk Support account before deployment.
Clean up the default code
Review the HTML file
A Zendesk app runs inside an iframe.
Static and dynamic elements are defined in the iframe.html file located in emnify-support-app/assets/iframe.html.
Set up the JavaScript file
Make sure this script tag is placed after the one for the ZAF SDK.
The body of iframe.html should now look as follows:
Design the app’s user interface
Add a footer
Add a footer with a Report bugs link:
Add styles
This guide uses Bootstrap CSS for styling.
Change the logo
Refer to Changing the logo in the Zendesk developer documentation for details on replacing the default logo with your own.
Set up authentication for the emnify REST API
For demonstration purposes only
The authentication token entered during app installation must be refreshed regularly to maintain functionality.
If the token becomes invalid, the app displays an error.
To resolve this, update the app settings in the Zendesk Admin Center and reenter the authToken.
This approach ensures that the authentication token isn’t exposed to the browser, which is especially important for organizations where access to the emnify Portal is restricted to specific users. However, this is a temporary solution designed for demonstration purposes and isn’t ideal for production use.
For a robust implementation, consider building a server-side Zendesk app that uses the application token to generate and refresh the auth_token dynamically.
If you want to read a guide for creating a server-side Zendesk apps and integrating with the emnify REST API, let the team know via Canny.
To access the emnify REST API, you need to authenticate your app.
The first step is to use your application token and the Retrieve Authentication Token call to generate a JSON Web Token (JWT) auth_token that authenticates further requests to the emnify REST API.
Follow Authenticate with application tokens to generate your auth_token.
This API path has a rate limit of 100 requests per IP in a 5-minute window. For more information, see Rate limits.
Define installation settings
Next, define the app’s installation settings to use the auth_token:
Define settings using the parameters property in the manifest file.
Add the following code:
For other supported properties, see Setting properties in the Zendesk developer documentation.
Use the authentication token in your app
The framework generates an HTML settings page based on the settings defined in the manifest file.
This is where an agent enters the authToken when installing the app or edit it later.
Then, you use the {{setting.authToken}} placeholder for the secure setting’s value in your app’s request call.
View device and SIM details
To help your team understand the condition of a device and SIM card, you can configure your app to fetch their current statuses from the emnify REST API and display them in the app.
This section includes:
- Creating the necessary templating to display the data.
- Pulling the ICCID value from the ticket.
- Using it to fetch the device and SIM details from the emnify REST API.
Pull the custom field value from ticket data
You can use ZAF to access Zendesk resources from your app. To retrieve the ICCID from the custom field you created earlier, use Zendesk’s Ticket API.
Zendesk apps uses a JavaScript library called the ZAF software development kit (SDK) to interact with the Zendesk API.
The SDK includes a client that provides an interface between your app and Zendesk Support, enabling various methods to interact with the Apps framework.
Key methods in the ZAF client
- request: Used to make HTTP requests to any REST API, including emnify’s.
- get: Used to retrieve data from the framework API, such as custom field values.
Steps to extract the ICCID
Use the client to access the ticket’s custom fields and extract the ICCID.
Create and insert a Handlebars template
Use Handlebars.js to display the fetched details in a structured format.
Create a template to display the information
Import the Handlebars library in your app by adding the following script to iframe.html (before the script importing your main.js file):
If you reload the app, nothing happens because you haven’t inserted the template in the HTML yet.
Insert the template into your app
Only one template can be rendered at a time.
Add the following function to your main.js file to render the template at runtime:
This function is generic and can be reused to render any Handlebars template in this guide.
Fetch device and SIM details
Next, identify which device the SIM card is linked to in the emnify platform using the List Endpoints API call.
Filter results using the q query parameter in the <field>:<criteria> format with the ICCID value.
Pass the ICCID to the showDeviceDetails and concatenate it to the request URL.
Start by defining the function before renderTemplate.
It should accept the ICCID as an input parameter because the ICCID uniquely identifies the SIM card and is used in the API request.
Since this function makes a network request, it can fail for reasons like network issues or incorrect data.
Use a try-catch block to handle both success and failure scenarios.
Inside the try block, use the client.request method to call the emnify REST API.
Pass the ICCID as part of the query parameter to filter the results and include authentication headers.
- URL: The base URL for the emnify Endpoint API.
- ICCID query:
q=iccid:${iccid}filters results to find a specific SIM. - Headers: Include the
Authorizationheader with the JWT token.
You need to mark secure as true to ensure sensitive information isn’t exposed in the browser.
For more information, see Zendesk’s secure setting property documentation.
The API response contains the details you need, such as the device name, ID, SIM status, etc. Extract these details from the response.
- Response parsing: The response is an array of devices.
Use the first device (
response[0]). - Store device ID: Save the device ID globally for later use.
- Format the data: Create an object with the required fields to display in the template.
Pass the deviceDetails object to a Handlebars template to render the information in the app.
Use the renderTemplate function you created earlier.
Putting it all together, the function looks like this:
Add error handling
Insert this Handlebars template in iframe.html after your details template:
The JavaScript logic for error handling is already included in the showDeviceDetails function.
Optional: Format the dates
You can format the date and time to display to be more human-readable.
View the device’s connectivity status
Now that you have the device details and defined the deviceId, you can fetch the device’s connectivity status from emnify using the Endpoint Connectivity Status API call.
Set up the Handlebars template
Before writing the JavaScript logic, you must define the Handlebars template in your HTML. This template renders the connectivity data dynamically at runtime.
Fetch the device’s connectivity status
Begin by defining the function in main.js.
It accepts deviceId as a parameter, which is the unique identifier for the device obtained from the emnify REST API.
As with showDeviceDetails, network requests in this function may fail.
Use a try-catch block to handle both success and error scenarios.
Inside the try block, use client.request to call the emnify REST API for the device’s connectivity status.
- URL: The base URL for the emnify Endpoint API entrypoint.
- Headers: Include the
Authorizationheader with the JWT token.
The response contains the device’s connectivity status. Extract the status description and format the current date to show when the information was last updated.
- Use the
formatDatefunction (defined earlier) to format the date.
Pass the connectivityData object to the renderTemplate function to populate and display the data in the app.
Here’s the completed showConnectivityStatus function:
Refresh device statuses
This section explains how to add and implement buttons under each information block, allowing agents to manually refresh the device and connectivity statuses.
Update the HTML
Incorporate buttons into your HTML structure in iframe.html under each information block:
Attach event listeners in JavaScript
Event listeners connect the buttons to the respective functions, ensuring that clicking them triggers data fetching and updates.
Add the following code to your main.js file:
How it works:
- Each button is uniquely identified using an id (
refresh-connectivityandrefresh-device-details). - On clicking the “Refresh Connectivity Status” button, the
showConnectivityStatusfunction is invoked using the storeddeviceId. - The “Refresh Device and SIM Details” button triggers the
showDeviceDetailsfunction, passing the ICCID (iccidFromCustomField).
Reset device connectivity
This section explains how to add and implement a button under the Device Connectivity Status block, allowing agents to reset connectivity for a device using emnify’s Reset Endpoint Connectivity API call. The button displays status updates during the process and refresh the connectivity status once the reset is complete.
Update the HTML
Add the “Reset Connectivity” button and a status span for feedback in your iframe.html file:
Implement the reset functionality
Begin by defining the resetConnectivity function.
By the end, this function:
- Updates the UI to indicate the reset process has started.
- Sends a
PATCHrequest to the connectivity reset API entrypoint. - Handles the response and update the UI accordingly.
- Display the updated connectivity status after a delay.
Inside the function, access the status span element (reset-connectivity-status) to provide feedback to the agent.
Update the text to “Processing…” and style it with a warning class to visually indicate that the reset process is ongoing.
The emnify REST API requires a payload with location and pdp_context.
For this guide, set these values to null.
Serialize this data into JSON format using JSON.stringify.
Next, prepare the headers for the API request. Include:
- An
Authorizationheader with the bearer token for authentication. - A
Content-Typeheader specifying that the payload is JSON.
By storing these headers in a variable, you maintain compatibility with the Zendesk app framework.
Use the client.request method to send a PATCH request to the emnify REST API.
The deviceId is passed in the URL to specify the device to be reset.
If the request is successful:
- Update the status span with a success message, informing the agent that the reset process has started.
- Advise the agent to keep the tab open while waiting for the updated status.
- Use a
setTimeoutfunction to fetch the new connectivity status after two minutes.When reset connectivity is triggered, the device detaches from the network and waits for the modem to connect again. Depending on the device and network conditions, this process can take a few seconds to a few minutes. The connectivity status fetched may not be accurate unless you add a delay.
Here’s how the complete resetConnectivity function looks:
Install the app in Zendesk
If you haven’t already, install ZCLI then follow the steps from the Zendesk developer documentation to Install the private app in Zendesk Support.