> ## 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 Building Blocks

> Export Building Blocks by Environment ID and Workspace ID. <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`</td> <td> `-H "Accept:text/plain;language=rego"`</td>
</tbody> </table> <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/building-blocks/{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/building-blocks/{envId}": {
      "get": {
        "tags": [
          "Policy Building Blocks Management APIs 2.0"
        ],
        "summary": "Export Building Blocks",
        "description": "Export Building Blocks by Environment ID and Workspace ID. <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`</td> <td> `-H \"Accept:text/plain;language=rego\"`</td>\n</tbody> </table> <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>",
        "operationId": "listBuildingBlocks",
        "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 if `identityWsId` is not provided.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "filter[identityWsId]",
            "description": "Identity Workspace ID. *Required if `authWsId` is not provided.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "in": "query",
            "name": "filter[kind]",
            "description": "Kinds of Building Block Filters. *Required if at least one of the following filters are provided:`filter[id]`, `filter[name]`,`filter[templateId]`.",
            "schema": {
              "type": "string",
              "enum": [
                "dynamic-group",
                "ruleset",
                "condition",
                "condition-identity",
                "condition-request",
                "condition-ip"
              ]
            }
          },
          {
            "in": "query",
            "name": "filter[id]",
            "description": "Building Block ID Filter",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "filter[id][in]",
            "description": "Filter for multiple Building Block IDs. *Required if `filter[id]` is not provided.",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "in": "query",
            "name": "filter[name]",
            "description": "Building Block Name Filter",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "filter[templateId]",
            "description": "Building Block Template ID Filter",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "filter[policyId]",
            "description": "Policy ID Filter. Only returns Building Blocks associated with the Policy provided.",
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "query",
            "name": "filter[policyId][in]",
            "description": "Filter by multiple Policy IDs. Only returns Building Blocks associated with the Policies provided.",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          },
          {
            "in": "query",
            "name": "extendedSchema",
            "description": "Toggle to enable or disable additional metadata in the response, like the Building Block `id` and `description`.",
            "schema": {
              "type": "boolean",
              "default": "true"
            }
          }
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "successful operation",
            "headers": {
              "x-request-id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "text/plain;language=rego": {
                "schema": {
                  "type": "string",
                  "description": "Building Blocks as Rego code"
                },
                "examples": {
                  "Dynamic Groups": {
                    "value": "package building_blocks\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: dg1\ndynamic_group(identity) if {\n  identity.template == \"idWs1\"\n  identity[\"idAttr1\"] == \"test\"\n  identity[\"idAttr1\"] != \"prod\"\n}\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: DynamicGroup\n#     name: dg2\n#     id: 0a738db8-b669-4e33-a8db-97eee5d856d1\n#     description: dg2\ndynamic_group(identity) if {\n  identity.template == \"idWs1\"\n  contains(identity[\"idAttr1\"], \"admin\")\n}\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: DynamicGroup\n#     name: dg3\n#     id: 2539fb2b-c238-49cd-b6f0-65cf1aa65feb\n#     description: dg3\ndynamic_group(identity) if {\n  identity.template == \"idWs1\"\n  identity[\"idAttr1\"] != \"stage\"\n}\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: DynamicGroup\n#     name: idWs1 All Users\n#     id: 6de6071c-4d30-4a77-9e40-106dded2194e\n#     description: default dg\ndynamic_group(identity) if {\n  identity.template == \"idWs1\"\n}\n"
                  },
                  "RuleSets and Conditions": {
                    "value": "package building_blocks\nimport rego.v1\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: Ruleset\n#     name: All Assets\n#     id: 69fedeb9-1a36-4e57-bd6c-3d22ccff1d06\n#     description: \"Predefined Ruleset. All Assets contains all created assets defined in the Asset Type\"\nruleset(asset, identity, requestParams, action) if {\n  asset.template == \"at1\"\n}\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: Ruleset\n#     name: rs1\n#     id: e9bc705a-cbdc-4f6f-9e4d-d7063bf9a791\n#     description: \"RuleSet 1\"\nruleset(asset, identity, requestParams, action) if {\n  asset.template == \"at1\"\n  asset[\"attr1\"] == \"doc\"\n}\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: Ruleset\n#     name: rs2\n#     id: 43129fab-da16-423e-a267-9385a8610f51\n#     description: \"Rule Set 2\"\nruleset(asset, identity, requestParams, action) if {\n  asset.template == \"at1\"\n  identity.template == \"idWs1\"\n  contains(asset[\"attr1\"], identity[\"idAttr1\"])\n}\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: Ruleset\n#     name: rs3\n#     id: 5969938d-d579-409b-bae8-467281db8545\n#     description: \"RuleSet 3\"\nruleset(asset, identity, requestParams , action) if {\n  asset.template == \"at1\"\n  asset[\"attr1\"] == \"foo3\"\n}\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: Condition IP\n#     name: c1\n#     id: fdee702c-2406-4608-bf58-a6d0791b6ed3\n#     description: \"Cond 1\"\ncondition_ip(env) if {\n  net.cidr_contains(\"10.0.0.0/10\", env.sourceIp)\n}\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: Condition Identity\n#     name: c2\n#     id: 133875fb-bff2-46b1-b9ea-a6c25225ba6f\n#     description: \"Cond 2\"\ncondition_identity(identity) if {\n  identity.template == \"idWs1\"\n  startswith(identity[\"idAttr1\"], \"qa\")\n}\n\n# METADATA\n# custom:\n#   plainid:\n#     kind: Condition Request\n#     name: c3\n#     id: 2b37e468-a7ea-4039-ac35-5195da9f0b8a\n#     description: \"Cond 3\"\ncondition_request(requestParams, identity) if {\n  identity.template == \"idWs1\"\n  requestParams[\"role\"] == identity[\"idAttr1\"]\n}\n"
                  },
                  "Generic Conditions": {
                    "value": "package building_blocks\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\n# METADATA\n# custom:\n#   plainid:\n#     kind: Condition\n#     subKind: Platforms\n#     name: Windows Only\n#     id: bbb22222-2222-2222-2222-222222222222\ncondition(requestParams) if {\n  requestParams[\"Platform\"] == \"Windows\"\n}\n"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "headers": {
              "x-request-id": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "bad request",
            "headers": {
              "x-request-id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                },
                "examples": {
                  "Identity WS not found": {
                    "value": {
                      "errors": [
                        {
                          "code": "PAC-005",
                          "args": {
                            "0": "67c1ffe0-a540-4662-b894-0813abcc04ec"
                          },
                          "id": "ERHCQC",
                          "status": "400",
                          "name": "IdentityWsNotFound",
                          "message": "IdentityWs: [67c1ffe0-a540-4662-b894-0813abcc04ec] not found"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "not found",
            "headers": {
              "x-request-id": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Errors"
                },
                "examples": {
                  "Building Blocks not found": {
                    "value": {
                      "errors": [
                        {
                          "code": "PAC-005",
                          "args": {
                            "0": "67c1ffe0-a540-4662-b894-0813abcc04ec"
                          },
                          "id": "ERHCQC",
                          "status": "404",
                          "name": "BuildingBlocksNotFound",
                          "message": "Building Blocks not found"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "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": {
      "Errors": {
        "type": "object",
        "properties": {
          "errors": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "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"
              }
            }
          }
        }
      }
    }
  }
}
````

