---
agentTools:
  projectIndex: https://requestly.readme.io/llms.txt
---

# Get all Rules

# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "New Rules API spec",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api2.requestly.io/v1"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/rules": {
      "get": {
        "summary": "Retrieve a list of rules",
        "parameters": [
          {
            "in": "query",
            "name": "offset",
            "schema": {
              "type": "integer",
              "minimum": 0
            },
            "required": false,
            "description": "The index from where the results should start. Usually set to the value received in `nextOffset` from the previous response."
          },
          {
            "in": "query",
            "name": "pageSize",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 75,
              "default": 30
            },
            "required": false,
            "description": "Number of results to return. Maximum value is 75."
          }
        ],
        "responses": {
          "200": {
            "description": "Rules retrieved successfully",
            "content": {
              "application/json": {
                "example": {
                  "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"
                        }
                      ]
                    },
                    {
                      "id": "Cancel_a1b2c",
                      "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"
                          }
                        }
                      ]
                    },
                    {
                      "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"
                        }
                      ]
                    }
                  ],
                  "nextOffset": 2,
                  "total": 10
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Rule"
                      }
                    },
                    "nextOffset": {
                      "type": "integer",
                      "nullable": true,
                      "description": "The offset for the next page of results. Null if there are no more records."
                    },
                    "total": {
                      "type": "integer",
                      "description": "Total number of records available"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadPageFilters"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedResponse"
          },
          "429": {
            "description": "Too Many Requests"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "responses": {
      "UnauthorizedResponse": {
        "description": "Unauthorized action",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CommonResponse"
            }
          }
        }
      },
      "BadPageFilters": {
        "description": "Bad request due to invalid pagination parameters",
        "content": {
          "application/json": {
            "schema": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/CommonResponse"
                },
                {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "enum": [
                        "Offset should be a number",
                        "Offset cannot be negative",
                        "Page size should be a number",
                        "Page size cannot be negative"
                      ]
                    }
                  }
                }
              ]
            }
          }
        }
      }
    },
    "schemas": {
      "CommonResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "RuleType": {
        "type": "string",
        "enum": [
          "Redirect",
          "Cancel",
          "Replace",
          "Headers",
          "UserAgent",
          "Script",
          "QueryParam",
          "Response",
          "Request",
          "Delay"
        ],
        "default": "Redirect"
      },
      "Status": {
        "type": "string",
        "enum": [
          "Active",
          "Inactive"
        ],
        "default": "Inactive"
      },
      "Rule": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "lastModifiedBy": {
            "type": "string"
          },
          "modificationDate": {
            "type": "integer"
          },
          "creationDate": {
            "type": "integer"
          },
          "createdBy": {
            "type": "string"
          },
          "currentOwnerId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "objectType": {
            "type": "string",
            "enum": [
              "group",
              "rule"
            ]
          },
          "ruleType": {
            "$ref": "#/components/schemas/RuleType"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "groupId": {
            "type": "string"
          },
          "pairs": {
            "type": "array",
            "items": {
              "discriminator": {
                "propertyName": "ruleType",
                "mapping": {
                  "Script": "#/components/schemas/ScriptRulePair",
                  "Redirect": "#/components/schemas/RedirectRulePair",
                  "Cancel": "#/components/schemas/CancelRulePair",
                  "Replace": "#/components/schemas/ReplaceRulePair",
                  "Headers": "#/components/schemas/HeadersRulePair",
                  "UserAgent": "#/components/schemas/UserAgentRulePair",
                  "QueryParam": "#/components/schemas/QueryParamRulePair",
                  "Response": "#/components/schemas/ResponseRulePair",
                  "Request": "#/components/schemas/RequestRulePair",
                  "Delay": "#/components/schemas/DelayRulePair"
                }
              },
              "oneOf": [
                {
                  "$ref": "#/components/schemas/ScriptRulePair"
                },
                {
                  "$ref": "#/components/schemas/RedirectRulePair"
                },
                {
                  "$ref": "#/components/schemas/CancelRulePair"
                },
                {
                  "$ref": "#/components/schemas/ReplaceRulePair"
                },
                {
                  "$ref": "#/components/schemas/HeadersRulePair"
                },
                {
                  "$ref": "#/components/schemas/UserAgentRulePair"
                },
                {
                  "$ref": "#/components/schemas/QueryParamRulePair"
                },
                {
                  "$ref": "#/components/schemas/ResponseRulePair"
                },
                {
                  "$ref": "#/components/schemas/RequestRulePair"
                },
                {
                  "$ref": "#/components/schemas/DelayRulePair"
                }
              ]
            }
          },
          "isSample": {
            "type": "boolean"
          },
          "isFavourite": {
            "type": "boolean"
          }
        }
      },
      "RulePairSource": {
        "type": "object",
        "example": {
          "key": "Url",
          "operator": "Equals",
          "value": "https://www.google.com"
        },
        "required": [
          "key",
          "operator",
          "value"
        ],
        "properties": {
          "key": {
            "type": "string",
            "enum": [
              "Url",
              "host",
              "path"
            ],
            "default": "Url"
          },
          "operator": {
            "type": "string",
            "enum": [
              "Equals",
              "Contains",
              "Matches",
              "Wildcard_Matches"
            ],
            "default": "Equals"
          },
          "value": {
            "type": "string"
          },
          "filters": {
            "type": "array",
            "default": [],
            "items": {
              "type": "object",
              "properties": {
                "requestMethod": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "GET",
                      "POST",
                      "PUT",
                      "DELETE",
                      "PATCH",
                      "HEAD",
                      "OPTIONS"
                    ],
                    "example": "GET"
                  }
                },
                "resourceType": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "xmlhttprequest",
                      "script",
                      "stylesheet",
                      "image",
                      "media",
                      "font",
                      "websocket",
                      "main_frame",
                      "sub_frame"
                    ],
                    "example": "script"
                  }
                },
                "requestPayload": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "RedirectRulePair": {
        "type": "object",
        "required": [
          "source",
          "destinationType",
          "destination"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "destinationType": {
            "type": "string",
            "enum": [
              "url",
              "map_local",
              "mock_or_file_picker"
            ]
          },
          "destination": {
            "type": "string"
          }
        }
      },
      "CancelRulePair": {
        "type": "object",
        "required": [
          "source"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          }
        }
      },
      "ReplaceRulePair": {
        "type": "object",
        "required": [
          "source",
          "from",
          "to"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          }
        }
      },
      "HeadersRulePair": {
        "type": "object",
        "required": [
          "source",
          "modifications"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "modifications": {
            "type": "object",
            "required": [
              "Request",
              "Response"
            ],
            "default": {},
            "properties": {
              "Request": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/HeadersRuleModificationData"
                }
              },
              "Response": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/HeadersRuleModificationData"
                }
              }
            }
          }
        }
      },
      "HeadersRuleModificationData": {
        "type": "object",
        "required": [
          "header",
          "type"
        ],
        "properties": {
          "header": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "Add",
              "Remove",
              "Modify"
            ],
            "default": "Add"
          },
          "value": {
            "type": "string"
          }
        }
      },
      "UserAgentRulePair": {
        "type": "object",
        "required": [
          "source",
          "userAgent"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "userAgent": {
            "type": "string",
            "default": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion",
            "example": "Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion"
          },
          "env": {
            "type": "string"
          },
          "envType": {
            "type": "string",
            "enum": [
              "browser",
              "device",
              "custom"
            ],
            "default": "device"
          }
        }
      },
      "QueryParamRulePair": {
        "type": "object",
        "required": [
          "source",
          "modifications"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "modifications": {
            "type": "array",
            "default": [],
            "items": {
              "$ref": "#/components/schemas/QueryParamRuleModification"
            }
          }
        }
      },
      "QueryParamRuleModification": {
        "type": "object",
        "required": [
          "param",
          "type"
        ],
        "properties": {
          "param": {
            "type": "string"
          },
          "value": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "Add",
              "Remove",
              "Modify"
            ],
            "default": "Add"
          }
        }
      },
      "ScriptRulePair": {
        "type": "object",
        "required": [
          "source",
          "scripts"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "scripts": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "codeType": {
                  "type": "string",
                  "enum": [
                    "js",
                    "css"
                  ],
                  "default": "js"
                },
                "fileName": {
                  "type": "string"
                },
                "loadTime": {
                  "type": "string",
                  "default": "afterPageLoad"
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "code"
                  ]
                },
                "value": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "ResponseRulePair": {
        "type": "object",
        "required": [
          "source",
          "response"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "response": {
            "type": "object",
            "example": {
              "type": "code",
              "value": "function modifyResponse(args) { const {method, url, response, responseType, requestHeaders, requestData, responseJSON} = args; console.log(\"method\", method)\nreturn response; }",
              "resourceType": "restApi",
              "statusCode": "200"
            },
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "code",
                  "static"
                ],
                "default": "static"
              },
              "value": {
                "type": "string",
                "default": "{\"foo\": \"bar\"}"
              },
              "resourceType": {
                "type": "string",
                "enum": [
                  "restApi",
                  "graphqlApi",
                  "static"
                ],
                "default": "restApi"
              },
              "statusCode": {
                "type": "string",
                "default": "200"
              }
            }
          }
        }
      },
      "RequestRulePair": {
        "type": "object",
        "required": [
          "source",
          "request"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "request": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "code",
                  "static"
                ],
                "default": "static"
              },
              "value": {
                "type": "string",
                "default": "{\"foo\": \"bar\"}"
              },
              "statusCode": {
                "type": "string",
                "default": "200"
              }
            }
          }
        }
      },
      "DelayRulePair": {
        "type": "object",
        "required": [
          "source",
          "delay"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "delay": {
            "type": "string"
          }
        }
      }
    }
  },
  "x-readme": {
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "_id": {
    "buffer": {
      "0": 102,
      "1": 163,
      "2": 30,
      "3": 50,
      "4": 141,
      "5": 209,
      "6": 124,
      "7": 0,
      "8": 83,
      "9": 27,
      "10": 191,
      "11": 226
    }
  }
}
```