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

# Replace Rule

# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Create / Update Replace Rule",
    "version": "1.0.0"
  },
  "servers": [
    {
      "url": "https://api2.requestly.io/v1"
    }
  ],
  "security": [
    {
      "ApiKeyAuth": []
    }
  ],
  "paths": {
    "/rules": {
      "post": {
        "requestBody": {
          "content": {
            "application/json": {
              "example": {
                "name": "Replace Google with Bing",
                "objectType": "rule",
                "ruleType": "Replace",
                "status": "Active",
                "pairs": [
                  {
                    "source": {
                      "key": "Url",
                      "operator": "Equals",
                      "value": "https://www.google.com"
                    },
                    "destination": "https://www.bing.com"
                  }
                ]
              },
              "schema": {
                "$ref": "#/components/schemas/ReplaceRuleRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rule created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean"
                    },
                    "data": {
                      "$ref": "#/components/schemas/RuleMetaData"
                    }
                  }
                },
                "example": {
                  "success": true,
                  "data": {
                    "id": "12345",
                    "lastModifiedBy": "user123",
                    "modificationDate": 1629567600000,
                    "creationDate": 1629567600000,
                    "createdBy": "user123",
                    "currentOwnerId": "user123",
                    "name": "Replace Google with Bing",
                    "objectType": "rule",
                    "ruleType": "Replace",
                    "status": "Active",
                    "groupId": "",
                    "pairs": [
                      {
                        "source": {
                          "key": "Url",
                          "operator": "Equals",
                          "value": "https://www.google.com"
                        },
                        "destination": "https://www.bing.com"
                      }
                    ],
                    "isSample": false,
                    "isFavourite": false
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequestResponse"
          },
          "401": {
            "$ref": "#/components/responses/UnauthorizedResponse"
          },
          "404": {
            "$ref": "#/components/responses/NotFoundResponse"
          },
          "405": {
            "$ref": "#/components/responses/MethodNotAllowedResponse"
          },
          "429": {
            "description": "Too Many Requests"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key"
      }
    },
    "responses": {
      "BadRequestResponse": {
        "description": "Rule pairs or payload are invalid",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CommonResponse"
            }
          }
        }
      },
      "UnauthorizedResponse": {
        "description": "Unauthorized action",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CommonResponse"
            }
          }
        }
      },
      "NotFoundResponse": {
        "description": "Rule or group not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CommonResponse"
            }
          }
        }
      },
      "MethodNotAllowedResponse": {
        "description": "Rule type update not allowed",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/CommonResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "CommonResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "RuleMetaData": {
        "type": "object",
        "required": [
          "id",
          "lastModifiedBy",
          "modificationDate",
          "creationDate",
          "createdBy",
          "name",
          "objectType",
          "ruleType",
          "status",
          "groupId",
          "pairs",
          "isSample",
          "isFavourite"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "lastModifiedBy": {
            "type": "string"
          },
          "modificationDate": {
            "type": "integer",
            "format": "int64"
          },
          "creationDate": {
            "type": "integer",
            "format": "int64"
          },
          "createdBy": {
            "type": "string"
          },
          "currentOwnerId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "objectType": {
            "type": "string",
            "enum": [
              "rule"
            ],
            "default": "rule"
          },
          "ruleType": {
            "type": "string",
            "enum": [
              "Replace"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "Active",
              "Inactive"
            ]
          },
          "groupId": {
            "type": "string",
            "default": ""
          },
          "pairs": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReplaceRulePair"
            }
          },
          "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"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "ReplaceRuleRequest": {
        "type": "object",
        "required": [
          "name",
          "objectType",
          "ruleType",
          "status",
          "pairs"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "objectType": {
            "type": "string",
            "enum": [
              "rule"
            ],
            "default": "rule"
          },
          "ruleType": {
            "type": "string",
            "enum": [
              "Replace"
            ],
            "default": "Replace"
          },
          "status": {
            "type": "string",
            "enum": [
              "Active",
              "Inactive"
            ],
            "default": "Inactive"
          },
          "pairs": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ReplaceRulePair"
            }
          }
        }
      },
      "ReplaceRulePair": {
        "type": "object",
        "required": [
          "source",
          "from",
          "to"
        ],
        "properties": {
          "source": {
            "$ref": "#/components/schemas/RulePairSource"
          },
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          }
        }
      }
    }
  },
  "x-readme": {
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "_id": {
    "buffer": {
      "0": 100,
      "1": 243,
      "2": 120,
      "3": 56,
      "4": 118,
      "5": 118,
      "6": 25,
      "7": 0,
      "8": 36,
      "9": 119,
      "10": 204,
      "11": 122
    }
  }
}
```