Note: This article requires scripts. The examples here are Python scripts.

The RankSense API allows you to publish SEO rules via scripts. This can expedite the process of importing, tagging and publishing if you have many rules sheets.

The steps to use the API are as follows:

1) Prepare rules sheets

Prepare your rules sheets as usual. Full details can be found in the article “How to create custom SEO changes or ‘rules.’

2) Connect Google Drive

Connect Google Drive to the account that contains the rules sheets.

3) Get information that the API needs

The API needs the following:

3a) API token

In RankSense, click your user name in the top right, then My Profile.

03%20my%20profile

You will need the API key listed next to “Read write.” You can click the icon at right to copy it to the clipboard.

02a%20api%20key

3b) The website ID

Check the URL of your RankSense dashboard. The website ID is found here:

3c) The rules sheet URL

You will need the URL of each sheet you plan to publish.

3d) Tag IDs

Tagging your rules is optional but recommended. Applying tags now will help you validate the effectiveness of your changes later.

For each tag you wish to apply, please check the complete list of tag IDs. You will need the number that corresponds to each tag you wish to use.

You can choose multiple tags, i.e. one issue tag, one solution tag, and one affected tag. Be aware that the tags that you choose will be applied to every URL on the sheet. If you would like to apply different tags to certain URLs, please create a separate sheet.

4) Import rules with script

Here is the format of the script to import rules using Python:

#pip install requests 
import requests

requests.post(url='https://cf-app.ranksense.com/agile-seo/rules-api/import', data={
"token": "rse-api-token",
"sheet_link": "https://docs.google.com/spreadsheets/d/link", "website_id": 0,
"tags": [0, 1, 2]
})

Items to modify

URL
The URL that you use in the first line of the script will depend on whether you are publishing to staging or production. We recommend to publish to staging first, verify your changes, then publish to production.

To import to staging, use this URL:
https://cf-app.ranksense.com/stage-agile-seo/rules-api/import

To import to production, use this URL:
https://cf-app.ranksense.com/agile-seo/rules-api/import

Token
This is the API token that you found in your profile.

Sheet_link
This is the URL of the rules sheet.

Website_ID
This is the website ID from the URL of your RankSense dashboard.

Tags (optional)
These are the tag IDs you chose to apply to the rules you are importing. Add the ID numbers as an array.

5) Publish rules with script

Here is the format of the script to import rules using Python:

#pip install requests 
import requests

requests.post(url='https://cf-app.ranksense.com/agile-seo/rules-api/publish', data={
"token": "rse-api-token",
"website_id": 0,
"environment": "PRODUCTION"
})

Items to modify

URL
To publish to staging, use this URL:
https://cf-app.ranksense.com/stage-agile-seo/rules-api/publish

To publish to production, use this URL:
https://cf-app.ranksense.com/agile-seo/rules-api/publish

Token
This is the API token that you found in your profile.

Website ID
This is the website ID from the URL of your RankSense dashboard.

Environment
Enter one of the following: STAGING, PRODUCTION, MONITORING


6) Verify changes

For changes that were applied to production, you can verify the changes directly on the live site.

For changes that were applied to staging, please use the RankSense Chrome extension to verify the changes.

Did this answer your question?