πŸ““

Endpoints β€” Rules API

Getting Started
Installation
Setup
Inspect Traffic
HTTP Rules (Modify Traffic)
Session Book
Mock Server
API Client
File Server
Workspace
Public API
Guides
TroubleShooting
Subscription & Billing
Getting Started
Installation
Setup
Inspect Traffic
API Client
HTTP Rules (Modify Traffic)
Mock Server
File Server
Workspace
Public API
Guides
Session Book
Subscription & Billing
TroubleShooting
Β 
Β 

Authentication

To authenticate with the API, use the custom header x-api-key with your provided API key.
Example:
curl -H "x-api-key: YOUR_API_KEY" https://api2.requestly.io/v1/rules
🎁
Requestly API is currently in BETA. Fill this form to get your API key today.

Endpoints

The current APIs give all the basic crud capabilities for rules. In case you want to quickly try these out on this playground https://requestly.readme.io/

Get rules

You have the option to either get all the rules or get a certain

Get all rules

To retrieve all the rules, use the following endpoint.
Endpoint: GET /rules
CURL Example:
curl -H "x-api-key: YOUR_API_KEY" https://api2.requestly.io/v1/rules
Sample Response:
{ "success": true, "data": [ { "id": "Redirect_fohh4", "name": "Sample Redirect Rule", "description": "This rule redirects example.com to newexample.com", "status": "Active", "ruleType": "Redirect", "pairs": [ { "source": { "key": "Url", "operator": "Equals", "value": "<https://example.com>" }, "destinationType": "url", "destination": "<https://newexample.com>" } ] }, // ... other rules ] }

Get a particular rule

To retrieve a specific rule, use the rule's unique ID.
Endpoint: GET /rules/:ruleId
CURL Example:
curl -H "x-api-key: YOUR_API_KEY" https://api2.requestly.io/v1/rules/Redirect_fohh4
Sample Response:
{ "success": true, "data": { "id": "Redirect_fohh4", "name": "Sample Redirect Rule", "description": "This rule redirects example.com to newexample.com", "status": "Active", "ruleType": "Redirect", "pairs": [ { "source": { "key": "Url", "operator": "Equals", "value": "<https://example.com>" }, "destinationType": "url", "destination": "<https://newexample.com>" } ] } }

Create Rule

To create a new rule, send a POST request with the rule details.
Endpoint: POST /rules
CURL Example:
curl -X POST -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{ "name": "Cancel Rule for Blocked Site", "description": "This rule blocks access to blockedsite.com", "status": "Active", "ruleType": "Cancel", "pairs": [ { "source": { "key": "Url", "operator": "Equals", "value": "https://blockedsite.com" } } ] }' https://api2.requestly.io/v1/rules
Sample Response:
{ "success": true, "data": { "id": "Cancel_a1b2c", "name": "Cancel Rule for Blocked Site", "description": "This rule blocks access to spammy.com", "status": "Active", "ruleType": "Cancel", "pairs": [ { "source": { "key": "Url", "operator": "Equals", "value": "https://spammy.com" } } ] } }

Update Rule

To update an existing rule, send a PUT request with the updated rule details.
Endpoint: PUT /rules/:ruleId
CURL Example:
curl -X PUT -H "x-api-key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{ "name": "Replace Rule for Typo", "description": "This rule replaces typodomain.com with correctdomain.com", "status": "Active", "ruleType": "Replace", "pairs": [ { "source": { "key": "Url", "operator": "Equals", "value": "https://typodomain.com" }, "from": "typodomain.com", "to": "correctdomain.com" } ] }' https://api2.requestly.io/v1/rules/Replace_z5x6y
Sample Response:
{ "success": true, "data": { "id": "Replace_z5x6y", "name": "Replace Rule for Typo", "description": "This rule replaces typodomain.com with correctdomain.com", "status": "Active", "ruleType": "Replace", "pairs": [ { "source": { "key": "Url", "operator": "Equals", "value": "https://typodomain.com" }, "from": "typodomain.com", "to": "correctdomain.com" } ] } }

Delete Rule

To delete a rule, send a DELETE request specifying the rule's unique ID.
Endpoint: DELETE /rules/:ruleId
CURL Example:
curl -X DELETE -H "x-api-key: YOUR_API_KEY" https://api2.requestly.io/v1/rules/Headers_w3e4r
Sample Response:
{ "success": true, "message": "Rule successfully deleted." }

Possible Errors

  • Rule not found: The specified rule does not exist.
  • Unauthorized action: You do not have access to the specified rule.
  • Group not found: The specified group does not exist.
  • Rule pairs are invalid: The provided rule pairs do not match the expected schema.
  • Rule Payload is invalid: The entire rule payload is invalid.
  • Rule Type update not allowed: Attempted to change the rule type after creation.
Each error will return a response in the format:
{ "success": false, "message": "Error message here." }