---
title: Query files by metadata
slug: tech-docs/query-files-by-metadata
docTags: 
createdAt: 2026-07-20T10:12:05.627Z
---

{
  "id": "IC_N75zEdu2QwtrW9w_Sa",
  "type": "api-oas-v2",
  "data": {
    "method": "POST",
    "url": "/api/v1/search-files",
    "servers": [],
    "name": "Query files by metadata",
    "description": "",
    "contentType": "application/json",
    "request": {
      "pathParameters": [],
      "headerParameters": [
        {
          "name": "accept",
          "type": "string",
          "kind": "optional",
          "description": "Generated from available response content types",
          "enum": [
            "application/json"
          ],
          "default": "application/json"
        },
        {
          "kind": "required",
          "name": "Site-Id",
          "type": "string",
          "example": "jones-climbing",
          "description": "Spark Layer Site ID"
        }
      ],
      "queryParameters": [],
      "bodyDataParameters": [
        {
          "kind": "required",
          "name": "body",
          "type": "object",
          "description": "",
          "schema": [
            {
              "name": "metadata",
              "kind": "required",
              "type": "",
              "nullable": true,
              "description": "<p>Returns all files who's metadata contains this JSON. See: <a href=\"https://www.postgresql.org/docs/current/datatype-json.html#JSON-CONTAINMENT\" target=\"_blank\">https://www.postgresql.org/docs/current/datatype-json.html#JSON-CONTAINMENT</a></p>",
              "example": "{\"sparklayer\":{\"forms\":{\"context\":\"email_template\"}}}"
            }
          ],
          "isExpanded": true
        }
      ],
      "formDataParameters": [],
      "oAuthParameters": [],
      "cookieParameters": []
    },
    "responses": [
      {
        "statusCode": "200",
        "description": "Success",
        "jsonExample": "",
        "isExpanded": true,
        "schema": [
          {
            "kind": "optional",
            "type": "array",
            "description": "",
            "schema": [
              {
                "name": "file_handle",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "",
                "modelRef": "#/components/schemas/FileHandle",
                "customType": "FileHandle",
                "schema": [
                  {
                    "name": "file_path",
                    "kind": "optional",
                    "type": "string",
                    "readOnly": true,
                    "description": "<p>The path to the file, including the file name</p>",
                    "example": "folder/file.png"
                  },
                  {
                    "name": "id",
                    "kind": "optional",
                    "type": "string",
                    "readOnly": true,
                    "description": "The ID of this type",
                    "example": "86027e2c-e853-11ee-b1d4-7c214a6ed8c7"
                  },
                  {
                    "name": "url",
                    "kind": "optional",
                    "type": "string",
                    "readOnly": true,
                    "nullable": true,
                    "description": "<p>URL to download/upload the file. For GET, this will be a readable link. If the file is not ready, this will be <code>null</code>. For POST/PATCH this will be a writeable link</p>",
                    "example": "https://files.sparklayer.io/siteId/siteEnv/path/to/file.png."
                  },
                  {
                    "name": "required_headers",
                    "kind": "optional",
                    "type": "array",
                    "readOnly": true,
                    "description": "<p>An array of headers you must include in the file upload/download request</p>",
                    "example": "",
                    "itemType": "object",
                    "customType": "object[]",
                    "schema": [
                      {
                        "name": "name",
                        "kind": "optional",
                        "type": "string",
                        "readOnly": true,
                        "description": "Name of the header",
                        "example": "Content-Type"
                      },
                      {
                        "name": "value",
                        "kind": "optional",
                        "type": "string",
                        "readOnly": true,
                        "description": "Value of the header",
                        "example": "application/pdf"
                      }
                    ]
                  }
                ]
              },
              {
                "name": "ready",
                "kind": "optional",
                "type": "boolean",
                "readOnly": true,
                "description": "Whether the file has been fully uploaded and verified",
                "example": true
              },
              {
                "name": "mime_type",
                "kind": "optional",
                "type": "string",
                "readOnly": true,
                "description": "The mime type of this file",
                "example": "image/png"
              },
              {
                "name": "file_size",
                "kind": "optional",
                "type": "integer",
                "readOnly": true,
                "description": "The size of this file in bytes",
                "example": 255
              },
              {
                "name": "created_at",
                "kind": "optional",
                "type": "string<date-time>",
                "readOnly": true,
                "description": "<p>The date at which the file was created (RFC-3339)</p>",
                "example": "2020-01-01T00:00:00+02:00",
                "format": "date-time"
              },
              {
                "name": "updated_at",
                "kind": "optional",
                "type": "string<date-time>",
                "readOnly": true,
                "description": "<p>The date at which the file was updated (RFC-3339)</p>",
                "example": "2020-01-01T00:00:00+02:00",
                "format": "date-time"
              },
              {
                "name": "metadata",
                "kind": "optional",
                "type": "object",
                "readOnly": true,
                "description": "",
                "example": "{\"sparklayer\":{\"forms\":{\"context\":\"email_template\",\"step_id\":\"erkjs\"},\"emails\":{\"attachments\":[\"86027e2c-e853-11ee-b1d4-7c214a6ed8c7\"]}}}",
                "schema": []
              },
              {
                "name": "rejected",
                "kind": "optional",
                "type": "boolean",
                "description": ""
              }
            ],
            "isExpanded": true
          }
        ]
      },
      {
        "statusCode": "default",
        "description": "Error Response",
        "jsonExample": "",
        "isExpanded": true
      }
    ],
    "hasXCodeSamples": false,
    "examples": {
      "languages": [
        {
          "id": "zspAHvyjpiURraoWi2wJe",
          "language": "curl",
          "label": "cURL",
          "code": "curl --request POST \\\n     --url /api/v1/search-files \\\n     --header 'accept: application/json' \\\n     --header 'content-type: application/json' \\\n     --header 'site-id: jones-climbing' \\\n     --data '{\n     \"metadata\": \"{\\\"sparklayer\\\":{\\\"forms\\\":{\\\"context\\\":\\\"email_template\\\"}}}\"\n     }'"
        },
        {
          "id": "727FD6QyZtNE4_H-HjUge",
          "language": "javascript",
          "label": "javascript",
          "code": "var myHeaders = new Headers();\nmyHeaders.append(\"accept\", \"application/json\");\nmyHeaders.append(\"content-type\", \"application/json\");\nmyHeaders.append(\"site-id\", \"jones-climbing\");\n\nvar raw = JSON.stringify({\n   \"metadata\": \"{\\\"sparklayer\\\":{\\\"forms\\\":{\\\"context\\\":\\\"email_template\\\"}}}\"\n});\n\nvar requestOptions = {\n   method: 'POST',\n   headers: myHeaders,\n   body: raw,\n   redirect: 'follow'\n};\n\nfetch(\"/api/v1/search-files\", requestOptions)\n   .then(response => response.text())\n   .then(result => console.log(result))\n   .catch(error => console.log('error', error));"
        },
        {
          "id": "VQBLRHxflXVWZBzPg0jjz",
          "language": "ruby",
          "label": "Ruby",
          "code": "require \"uri\"\nrequire \"json\"\nrequire \"net/http\"\n\nurl = URI(\"/api/v1/search-files\")\n\nhttp = Net::HTTP.new(url.host, url.port);\nrequest = Net::HTTP::Post.new(url)\nrequest[\"accept\"] = \"application/json\"\nrequest[\"content-type\"] = \"application/json\"\nrequest[\"site-id\"] = \"jones-climbing\"\nrequest.body = JSON.dump({\n   \"metadata\": \"{\\\"sparklayer\\\":{\\\"forms\\\":{\\\"context\\\":\\\"email_template\\\"}}}\"\n})\n\nresponse = http.request(request)\nputs response.read_body\n"
        },
        {
          "id": "TtGPcvkbN2v56RBJmXSqP",
          "language": "python",
          "label": "Python",
          "code": "import requests\nimport json\n\nurl = \"/api/v1/search-files\"\n\npayload = json.dumps({\n   \"metadata\": \"{\\\"sparklayer\\\":{\\\"forms\\\":{\\\"context\\\":\\\"email_template\\\"}}}\"\n})\nheaders = {\n   'accept': 'application/json',\n   'content-type': 'application/json',\n   'site-id': 'jones-climbing'\n}\n\nresponse = requests.request(\"POST\", url, headers=headers, data=payload)\n\nprint(response.text)\n"
        }
      ],
      "selectedLanguageId": "zspAHvyjpiURraoWi2wJe"
    },
    "results": {
      "languages": [
        {
          "id": "jrx6dGi3u1mdHWzZLn43F",
          "language": "200",
          "code": "// Success\n[\n  {\n    \"file_handle\": {\n      \"file_path\": \"folder/file.png\",\n      \"id\": \"86027e2c-e853-11ee-b1d4-7c214a6ed8c7\",\n      \"url\": \"https://files.sparklayer.io/siteId/siteEnv/path/to/file.png.\",\n      \"required_headers\": [\n        {\n          \"name\": \"Content-Type\",\n          \"value\": \"application/pdf\"\n        }\n      ]\n    },\n    \"ready\": true,\n    \"mime_type\": \"image/png\",\n    \"file_size\": 255,\n    \"created_at\": \"2020-01-01T00:00:00+02:00\",\n    \"updated_at\": \"2020-01-01T00:00:00+02:00\",\n    \"metadata\": {},\n    \"rejected\": false\n  }\n]"
        },
        {
          "id": "vr5xG9hkHIdRpdF1KEz_B",
          "language": "default",
          "code": "// Error Response\n"
        }
      ],
      "selectedLanguageId": "jrx6dGi3u1mdHWzZLn43F"
    }
  },
  "children": [
    {
      "text": ""
    }
  ]
}