Modify your API results with a javascript function

Modify Results is a new experimental feature that allows you to write javascript functions to transform your results to your liking. This lets you take your original API result data (scraped from the page) and perform operations on it (e.g. add/remove properties, do basic calculations, clean/normalize the data, sort and filter the results, etc).

You can access the Modify Results tab from the detail page:

screenshot of modify results function tab

 

To use modify functions, write your function in the Modify Results Function pane on the left. The function you write takes in the data argument, a javascript object representation of your APIs JSON endpoint. The modified version of your JSON endpoint will consist of whatever your function returns. You can preview, test and debug your function using the 'result peview' pane on the right which is updated each time you click Apply. Scroll down below the code windows or visit the examples page to see some simple code examples.

To access your modified endpoint, append the parameter &kimmodify=1 to your API call to apply your function to your results. 

Example:

Let's say I have API with API ID: zkvisgr9

To call this API without the modify function, your call looks like this:

https://kimonolabs.com/api/zkvisgr9?apikey=[yourAPIkey]

Now, to apply the modify function to the endpoint, the call looks like this:

https://kimonolabs.com/api/zkvisgr9?apikey=[yourAPIkey]&kimmodify=1

If you want to use a kimparameter and a modify results function at the same time, you can do that as well! For example, if you want to include the source urls for a crawl, you could call your api like this: 

https://kimonolabs.com/api/zkvisgr9?apikey=[yourAPIkey]&kimmodify=1&kimwithurl=1

Powered by Zendesk