> ## Documentation Index
> Fetch the complete documentation index at: https://docs.plainid.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Export Policy

> Export Policy by Environment ID and Workspace ID. This API supports different response formats based on the Accept header.
  <br> In the **Try It** section, view examples and code samples based on **Response format**, **Content Type (next to the Body title)**, and **Body** dropdowns.
<br>
<br><br><h2>Notice</h2>Accessing the Policy
Management APIs is through a dedicated domain/URL, according to your
PlainID Tenant Location<li><b>United States (US)</b> -
`https://api.us1.plainid.io`</li><li><b>Canada (CA)</b> -
`https://api.ca1.plainid.io`</li><li><b>Europe (EU)</b> -
`https://api.eu1.plainid.io`</li>
<br>
<h2>Using HTML Encoded Special Characters</h2>
<p>Use HTML encoded patterns when working with values that contain special characters like spaces, dashes, etc. Refer to this <a href="https://www.w3schools.com/tags/ref_urlencode.ASP" target="_blank">HTML URL Encoding Reference</a> for a full list.</p> <br>
<h2>Important note about headers</h2>
<p>Refer to the headers below to modify your cURL sample. Check if the following headers are in the sample, if not, ensure you add it to your cURL sample before pasting into your API tool. </p>
<h3>Headers</h3>
*Required
<table><thead>
<tr>
<th>Header</th>
<th>Value</th>
<th>cURL Line</th>
</tr></thead>
<tbody>
<tr>
<td>Accept</td>
<td>`text/plain;language=rego` or `application/json`</td>
<td> `-H "Accept:text/plain;language=rego"` or `-H "Accept:application/json"`</td>
<tr>
</tbody>
</table>
<i>
Note: Use <code>text/plain;language=rego</code> when exporting a Structured policy as Rego.<br/>
Use <code>application/json</code> when exporting either Structured or Native policy in JSON format.
See the examples below for more information.
</i>
<br><h3>cURL Sample Guidelines</h3><p>In order for the relevant parameters to appear in the cURL sample, you can input the values in the interactive API console on the right in the Try It or Code Sample tabs. You can then copy the cURL sample from the Code Sample tab in the correct format.</p>


## OpenAPI

````json GET /api/2.0/policies/{envId}
{
  "openapi": "3.0.3",
  "info": {
    "title": "Management APIs",
    "version": "1.0.0",
    "contact": {
      "name": "PlainID",
      "url": "https://plainid.com",
      "email": "contact@plainid.com"
    },
    "license": {
      "name": "Commercial",
      "url": "https://plainid.com/license"
    },
    "termsOfService": "https://www.plainid.com/terms/",
    "description": "<h3>The PlainID Authorization Platform provides Management capabilities through the APIs below.</h3><h4> To access the Management APIs, make sure to enter your dedicated domain according to your PlainID Tenant Location:<table><thead><tr><th>Region</th><th>Base URL</th></tr></thead><tbody><tr><td>United States (US)</td><td>https://api.us1.plainid.io</td></tr><tr><td>Canada (CA)</td><td>https://api.ca1.plainid.io</td></tr><tr><td>Europe (EU)</td><td>https://api.eu1.plainid.io</td></tr><tr><td>Local PAA</td><td>https://api.plainid.local</td></tr></tbody></table>"
  },
  "servers": [
    {
      "description": "United States",
      "url": "https://api.us1.plainid.io"
    },
    {
      "description": "Europe",
      "url": "https://api.eu1.plainid.io"
    },
    {
      "description": "Canada",
      "url": "https://api.ca1.plainid.io"
    },
    {
      "description": "Local PAA",
      "url": "https://api.plainid.local"
    }
  ],
  "paths": {
    "/api/2.0/policies/{envId}": {
      "get": {
        "tags": [
          "Policy Management APIs 2.0"
        ],
        "summary": "Export Policy",
        "description": "Export Policy by Environment ID and Workspace ID. This API supports different response formats based on the Accept header.\n  <br> In the **Try It** section, view examples and code samples based on **Response format**, **Content Type (next to the Body title)**, and **Body** dropdowns.\n<br>\n<br><br><h2>Notice</h2>Accessing the Policy\nManagement APIs is through a dedicated domain/URL, according to your\nPlainID Tenant Location<li><b>United States (US)</b> -\n`https://api.us1.plainid.io`</li><li><b>Canada (CA)</b> -\n`https://api.ca1.plainid.io`</li><li><b>Europe (EU)</b> -\n`https://api.eu1.plainid.io`</li>\n<br>\n<h2>Using HTML Encoded Special Characters</h2>\n<p>Use HTML encoded patterns when working with values that contain special characters like spaces, dashes, etc. Refer to this <a href=\"https://www.w3schools.com/tags/ref_urlencode.ASP\" target=\"_blank\">HTML URL Encoding Reference</a> for a full list.</p> <br>\n<h2>Important note about headers</h2>\n<p>Refer to the headers below to modify your cURL sample. Check if the following headers are in the sample, if not, ensure you add it to your cURL sample before pasting into your API tool. </p>\n<h3>Headers</h3>\n*Required\n<table><thead>\n<tr>\n<th>Header</th>\n<th>Value</th>\n<th>cURL Line</th>\n</tr></thead>\n<tbody>\n<tr>\n<td>Accept</td>\n<td>`text/plain;language=rego` or `application/json`</td>\n<td> `-H \"Accept:text/plain;language=rego\"` or `-H \"Accept:application/json\"`</td>\n<tr>\n</tbody>\n</table>\n<i>\nNote: Use <code>text/plain;language=rego</code> when exporting a Structured policy as Rego.<br/>\nUse <code>application/json</code> when exporting either Structured or Native policy in JSON format.\nSee the examples below for more information.\n</i>\n<br><h3>cURL Sample Guidelines</h3><p>In order for the relevant parameters to appear in the cURL sample, you can input the values in the interactive API console on the right in the Try It or Code Sample tabs. You can then copy the cURL sample from the Code Sample tab in the correct format.</p>\n",
        "operationId": "exportPolicy",
        "parameters": [
          {
            "in": "path",
            "name": "envId",
            "required": "true",
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "The Environment ID can be found under the Details Tab in the Environment Settings."
          },
          {
            "in": "query",
            "name": "filter[authWsId]",
            "description": "Authorization Workspace ID. This can be found in your Authorization Workspace Settings under Workspace ID.",
            "required": "true",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "filter[id]",
            "description": "Policy ID Filter",
            "required": "true",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "extendedSchema",
            "description": "Toggle to either enable or disable additional metadata, like the Policy `id` and `description`, in the response.",
            "schema": {
              "type": "boolean",
              "default": "true"
            }
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "successful operation",
            "headers": {
              "x-request-id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ExportPolicyResponse"
                },
                "examples": {
                  "Native Policy Response": {
                    "value": {
                      "data": {
                        "format": "json",
                        "policy": {
                          "policyId": "08ae32e4-fbf3-4cc8-b3b9-3b4061d1c825",
                          "name": "Bank Account Access Policy",
                          "description": "Policy for accessing bank accounts",
                          "accessType": "Allow",
                          "policyUse": "SAAS_APPLICATIONS",
                          "applications": [
                            {
                              "applicationId": "POP1V3WFXZ4PRIO",
                              "attributes": {
                                "vendorPolicyKind": "Row Access Policy",
                                "vendorPolicyName": "POL1",
                                "vendorPolicyOrder": "1",
                                "database": "DB",
                                "schema": "SCHEMA",
                                "owner": "ROLE"
                              },
                              "nativeCode": {
                                "language": "sql",
                                "code": "{\"policy\":\"CREATE OR REPLACE ROW ACCESS POLICY \"POL1\"\"}"
                              }
                            }
                          ]
                        }
                      }
                    }
                  },
                  "Structured Policy Response": {
                    "value": {
                      "data": {
                        "format": "rego",
                        "Structured Policy": "# METADATA\n# custom:\n#   plainid:\n#     policyId: 08ae32e4-fbf3-4cc8-b3b9-3b4061d1c825\n#     name: Manage personal account and Credit cards\n#     description: Customer can view and manage their own accounts an credit cards only with MFA\n#     accessType: Allow\npackage policy\nimport rego.v1\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: DynamicGroup\n#     name: dg1\n#     id: f28c17c2-caeb-4cf2-a549-02bf03fe4e17\n#     description: \"test DG\"\ndynamic_group(identity) if {\n  identity.template == \"idWs1\"\n  identity[\"idAttr1\"] == \"test\"\n  identity[\"idAttr1\"] != \"prod\"\n}\n"
                      }
                    }
                  },
                  "Structured Policy with Generic Condition Response": {
                    "value": {
                      "data": {
                        "format": "rego",
                        "Structured Policy": "# METADATA\n# custom:\n#   plainid:\n#     policyId: 08ae32e4-fbf3-4cc8-b3b9-3b4061d1c825\n#     name: Zscaler Country Code Policy\n#     description: Policy with generic condition for country codes\n#     accessType: Allow\n#     policyUse: SAAS_APPLICATIONS\n#     sourceEnvironmentId: 9c75b3ac-6165-4a5b-9783-e07dd5d2eb55\n#     applications: \n#       - id: ZScaler\n#         attributes:\n#            vendorPolicyKind: \"Access Policy\"\n#            ruleOrder: 35\n#            name: \"AAAZscalerBugTestZscalerSide\"\n#            id: \"72063538272665823\"\npackage policy\nimport rego.v1\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: Condition\n#     subKind: Country Codes\n#     name: Albania_Austria_Australia\n#     id: 8adc4fe8-759a-4df4-9dc1-c180c9c4a2c4\ncondition(requestParams) if {\n  requestParams[\"CountryCode\"] in [\"Albania\", \"Austria\", \"Australia\"]\n}\n",
                        "isPolicyCompleted": "true"
                      }
                    }
                  }
                }
              },
              "text/plain;language=rego": {
                "schema": {
                  "type": "string",
                  "description": "Policy as Rego code (only for structured policies)"
                },
                "examples": {
                  "Structured Policy": {
                    "value": "# METADATA\n# custom:\n#   plainid:\n#     policyId: 08ae32e4-fbf3-4cc8-b3b9-3b4061d1c825\n#     name: Manage personal account and Credit cards\n#     description: Customer can view and manage their own accounts an credit cards only with MFA\n#     accessType: Allow\npackage policy\nimport rego.v1\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: DynamicGroup\n#     name: dg1\n#     id: f28c17c2-caeb-4cf2-a549-02bf03fe4e17\n#     description: \"test DG\"\ndynamic_group(identity) if {\n  identity.template == \"idWs1\"\n  identity[\"idAttr1\"] == \"test\"\n  identity[\"idAttr1\"] != \"prod\"\n}\n"
                  },
                  "Structured Policy with Generic Condition": {
                    "value": "# METADATA\n# custom:\n#   plainid:\n#     policyId: 08ae32e4-fbf3-4cc8-b3b9-3b4061d1c825\n#     name: Zscaler Country Code Policy\n#     description: Policy with generic condition for country codes\n#     accessType: Allow\n#     policyUse: SAAS_APPLICATIONS\n#     sourceEnvironmentId: 9c75b3ac-6165-4a5b-9783-e07dd5d2eb55\n#     applications: \n#       - id: ZScaler\n#         attributes:\n#            vendorPolicyKind: \"Access Policy\"\n#            ruleOrder: 35\n#            name: \"AAAZscalerBugTestZscalerSide\"\n#            id: \"72063538272665823\"\npackage policy\nimport rego.v1\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: Condition\n#     subKind: Country Codes\n#     name: Albania_Austria_Australia\n#     id: 8adc4fe8-759a-4df4-9dc1-c180c9c4a2c4\ncondition(requestParams) if {\n  requestParams[\"CountryCode\"] in [\"Albania\", \"Austria\", \"Australia\"]\n}\n"
                  }
                }
              }
            }
          },
          "400": {
            "description": "bad request",
            "headers": {
              "x-request-id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                },
                "examples": {
                  "Authorization WS not found": {
                    "value": {
                      "errors": [
                        {
                          "code": "PAC-001",
                          "args": {
                            "0": "ceef5853-1491-4d1c-ae52-2f2a1729b3a4"
                          },
                          "id": "EWWOTR",
                          "status": "400",
                          "name": "AuthorizationWsNotFound",
                          "message": "AuthorizationWs: [ceef5853-1491-4d1c-ae52-2f2a1729b3a4] not found"
                        }
                      ]
                    }
                  },
                  "Structured policy not available": {
                    "value": {
                      "errors": [
                        {
                          "code": "PAC-012",
                          "id": "EWWOTR",
                          "status": "400",
                          "name": "StructuredPolicyNotAvailable",
                          "message": "Structured policy is not available"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "not found",
            "headers": {
              "x-request-id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                },
                "examples": {
                  "Policy not found": {
                    "value": {
                      "errors": [
                        {
                          "code": "PUA-033",
                          "args": {
                            "0": "a0a455bb-7dc3-4cd3-b0d2-86631ac75379",
                            "1": "ceef5853-1491-4d1c-ae52-2f2a1729b3a4"
                          },
                          "id": "E7WJBB",
                          "status": "404",
                          "name": "PolicyNotFoundError",
                          "message": "Policy Id doesn't exist in the environment"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "422": {
            "description": "Validation Failed - Invalid UUID",
            "headers": {
              "x-request-id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                },
                "examples": {
                  "Invalid ID Format": {
                    "value": {
                      "errors": [
                        {
                          "code": "V-032",
                          "args": {
                            "0": "ed252aa5-9d0c-4193-838-60bf20b13109",
                            "1": "uuid"
                          },
                          "id": "EEJQMA",
                          "status": "422",
                          "name": "UnprocessableEntityError",
                          "message": "$: test is an invalid uuid"
                        }
                      ]
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "ExportPolicyResponse": {
        "type": "object",
        "description": "Response object for export policy endpoint",
        "properties": {
          "data": {
            "$ref": "#/components/schemas/ExportPolicyByFormatResponse"
          },
          "meta": {
            "$ref": "#/components/schemas/meta"
          },
          "errors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Errors": {
        "type": "object",
        "properties": {
          "errors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "ExportPolicyByFormatResponse": {
        "type": "object",
        "properties": {
          "format": {
            "type": "string",
            "enum": [
              "json",
              "rego"
            ],
            "description": "The format of the exported policy"
          },
          "policy": {
            "oneOf": [
              {
                "type": "object",
                "description": "Native policy in JSON format",
                "properties": {
                  "policyId": {
                    "type": "string",
                    "description": "Policy ID"
                  },
                  "name": {
                    "type": "string",
                    "description": "Policy name"
                  },
                  "description": {
                    "type": "string",
                    "description": "Policy description"
                  },
                  "accessType": {
                    "type": "string",
                    "enum": [
                      "Allow",
                      "Deny"
                    ],
                    "description": "Policy access type"
                  },
                  "policyUse": {
                    "type": "string",
                    "description": "Policy usage type"
                  },
                  "applications": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "applicationId": {
                          "type": "string",
                          "description": "Application ID"
                        },
                        "attributes": {
                          "type": "object",
                          "description": "Application attributes",
                          "additionalProperties": "true"
                        },
                        "nativeCode": {
                          "type": "object",
                          "properties": {
                            "language": {
                              "type": "string",
                              "description": "Native code language (e.g., SQL, Python)"
                            },
                            "code": {
                              "type": "string",
                              "description": "Native code content"
                            }
                          }
                        }
                      }
                    }
                  },
                  "customAttributes": {
                    "type": "object",
                    "description": "Custom policy attributes",
                    "additionalProperties": "true"
                  }
                }
              },
              {
                "type": "string",
                "description": "Structured policy as Rego code string"
              }
            ]
          }
        },
        "x-stoplight": {
          "id": "export-policy-format-response"
        },
        "x-internal": "false"
      },
      "meta": {
        "type": "object",
        "description": "Response Meta",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of records"
          },
          "limit": {
            "type": "integer",
            "description": "Limit the number of records returned"
          },
          "offset": {
            "type": "integer",
            "description": "The starting point for return of records"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "id": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "name": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "args": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
````

