How to publish rules using our API
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:
- Prepare rules sheets.
- Connect Google Drive.
-
Get information that the API needs:
3a. API token
3b. The website ID
3c. The rules sheet URL
3d. Tag IDs
3e. API link - Import rules with script
- Publish rules with script
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.’”
Connect Google Drive
Connect Google Drive to the account that contains the rules sheets.
Get information that the API needs
The API needs the following:
API token
In RankSense, click your user name in the top right, then My Profile.
You will need the API key listed next to “Read write.” You can click the icon at right to copy it to the clipboard.
The website ID
Check the URL of your RankSense dashboard. The website ID is found here:
The rules sheet URL
You will need the URL of each sheet you plan to publish.
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.
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.
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