Backing up and restoring custom APIs and rules

Sometimes you might want to back up your custom rules – maybe you’re freezing your token for a while, or maybe you want to copy them to another token. In this short guide we’ll go through how to access all of your custom API rules and back them up for safe keeping.

Step 1: Access your rules

Our Custom API toolkit exposes an API for itself which you can use to display all your rules. Assuming your token is "MYTOKEN", here’s how you would access your rules: just visit the following URL in the browser:

This should produce a screen not unlike the following one:

Rules output

Rules output

This is a simple JSON file (not important if you don’t know what this means) which contains a list of all your custom API rules. The collapsed rules ({<->} in the image) are all different rules, but collapsed in the browser’s UI to make it more obvious that there are a lot of them. The code is made pretty with the help of this Chrome extension, if you need it.

Step 2: Save the file

To back up your rules, simply save this file somewhere onto the hard drive or your cloud storage with CMD/CTRL+S or File -> Save As. Make sure the file’s extension is .json, so for example myRules.json.

You can now store this file somewhere for later use. Alternatively, if you’re making changes to the rules make them and then save the file.

Importing the rules

So how do we use this file?

Using a handy tool like Postman, you would do the following:

  1. In a new request tab, you would enter the API URL: You can replace MYTOKEN with any token to which you want to upload the rules – does not have to be the one from which they were originally downloaded.

    Step 1

    Step 1
  2. Switch the method to POST

    Step 2

    Step 2
  3. In the "Body" tab, choose wither raw or binary. If you choose binary, then click on Choose Files and select the .json file we created earlier. If you choose raw, copy and paste that file’s content into the text area.

    Step 3

    Step 3
  4. Finally, under the Headers tab, add "Content-Type" as the key, and "application/json" as the value, so that Diffbot knows to expect JSON content.

    Step 4

    Step 4
  5. Press Send. This will upload the new rules into your token. You’ll get a response back that’s something like this:


    These are just IDs of the rules that were updated and can be safely ignored.