πŸ““

Endpoints: Rules API

Page Type
Meta Title
Meta Description
Category
Public API
Publish
Publish
Path
/api/endpoints
Β 
Β 

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

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." }