Create API bookmarklets
Last Update: Oct 2024 • Est. Read Time: 3 MINYou may find yourself needing to use our API documentation to access data within your Kustomer organization. This can be useful when trying to find specific data related to different KObjects, as well as when trying to customize, modify, and integrate with your Kustomer organization or an external service.
These API calls can be made to Kustomer endpoints by using a platform like Postman, or via cURL
commands in your terminal. However, this can be a time-consuming process by having multiple applications open with a lot of copying and pasting, especially when making a GET HTTP
request. Instead, you can set up bookmarklets to make GET
requests directly from your browser and quickly gather the data you want.
This tutorial will help you set up basic bookmarklets to make GET requests to some of Kustomer's most common endpoints, such as conversations, customers, messages, and more.
In this article
What is a bookmarklet?
Bookmarklets are similar to browser extensions as they perform actions on the webpage you are currently on with a single mouse click. Bookmarklets are stored in your browser like a traditional bookmark, but instead of having a web address attached to them, they have a snippet of JavaScript code which runs when you access the bookmark.
Bookmarklets can be added to any browser, and can make use of the session key your browser receives when logging in to your Kustomer organization to access our endpoints. We'll walk through some steps to add the JavaScript code to a bookmarklet, and you can repeat the process for each one you'd like to set up.
Set up a bookmarklet
The process of creating a bookmark and the keyboard shortcuts involved can vary from one browser to another, and whether you're on Windows or Mac. Learn more about your browser's specific bookmark process on the help centers for Google Chrome, Firefox, Microsoft Edge, and Safari.
To create a bookmarklet:
- Show the bookmark bar in your browser.
- If you plan to create multiple bookmarklets, we suggest you first create a bookmark folder to organize them.
- Create a new bookmark.
- Replace the URL of the bookmark with the JavaScript code snippet for the desired bookmark.
- Replace the Name of the bookmark with the name of the endpoint, like Conversation, Customer, Message, and so on.
- Save the bookmark.
- Repeat this process for any additional bookmarklets you'd like to create.
Code snippet examples
These code snippets are what you'll insert as the URL for the various bookmarklets you created in the prior step.
Conversation
javascript: (function() {var match = window.location.href.match(/(?:https\:\/\/)(.*)(?:\.kustomerapp\.com.*event\/)(.*)/); window.location = 'https://' + match[1] + '.api.kustomerapp.com/v1/conversations/' + match[2];}());
Customer
javascript: (function() {var match = window.location.href.match(/(?:https\:\/\/)(.*)(?:\.kustomerapp\.com\/app\/customers\/)(.*)(?:\/event)/); window.location = 'https://' + match[1] + '.api.kustomerapp.com/v1/customers/' + match[2];}());
Messages
javascript: (function() {var match = window.location.href.match(/(?:https\:\/\/)(.*)(?:\.kustomerapp\.com.*event\/)(.*)/); window.location = 'https://' + match[1] + '.api.kustomerapp.com/v1/conversations/' + match[2] + '/messages';}());
Events
javascript: (function() {var match = window.location.href.match(/(?:https\:\/\/)(.*)(?:\.kustomerapp\.com.*event\/)(.*)/); window.location = 'https://' + match[1] + '.api.kustomerapp.com/v1/conversations/' + match[2] + '/events';}());
Users
javascript: (function() {var match = window.location.href.match(/(?:https\:\/\/)(.*)(?:\.kustomerapp\.com)/);window.location = 'https://' + match[1] + '.api.kustomerapp.com/v1/users';}());
Knowledge Base Article
javascript: (function() {var match = window.location.href.match(/:\/\/([a-zA-Z-]*).*\/(\d.*\W)/);window.location = 'https://' + match[1] + '.api.kustomerapp.com/v1/kb/articles/' + match[2] + 'versions/en_us' ;}());
Generic v1 URL
Use this to make a GET
request with any of the endpoints listed in the Kustomer REST API documentation.
javascript: (function() {var match = window.location.href.match(/:\/\/([a-zA-Z-]*)/);window.location = 'https://' + match[1] + '.api.kustomerapp.com/v1/'}());
Using bookmarklets
Once the bookmarklets are set up, navigate to the part of the app where you would like to make a GET
request and click the bookmarklet link. This will navigate to a code view displaying the JSON that corresponds with the GET
request that was just made.
Note: Bookmarklets only work while viewing the appropriate page within Kustomer. You must be viewing a conversation within the Kustomer app to use the conversation, customer, messages, events, and users bookmarklets. Similarly, you must be viewing a knowledge base article within Kustomer to use the knowledge base bookmarklet.
The resulting JSON output might be a little difficult to read in the browser. To make this easier to review, you can copy the JSON to your favorite code editor or use a JSON viewer browser extension or add-ons. Some examples of popular extensions for this include JSON Viewer for Chrome and JSONView for Firefox.
Here is a comparison of viewing the JSON with and without a JSON viewer extension or add-on.