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

# GET /api/inject — Fetch Published Schemas as JSON

> Retrieve published JSON-LD schemas for a specific page URL. The SchemaGen SDK calls this endpoint automatically; you can also call it directly.

The inject endpoint returns all published schemas for a given page as a structured JSON response. The SchemaGen JavaScript SDK calls this endpoint automatically when it loads on your site, but you can also call it directly if you want to build a custom schema delivery layer or inspect what schemas are active for a specific URL.

<Note>
  This endpoint requires no authentication. It is a public CORS-enabled endpoint safe to call from browser JavaScript or any server environment.
</Note>

## Endpoint

```
GET https://schemagen.io/api/inject
```

## Query parameters

<ParamField query="clientId" type="string" required>
  The UUID of your client site. You can find your Client ID in **Settings → Client** in the SchemaGen dashboard.
</ParamField>

<ParamField query="url" type="string" required>
  The absolute URL of the page you want to fetch schemas for. Must include the protocol (e.g., `https://example.com/blog/my-post`). SchemaGen uses this to match published schemas scoped to that specific page.
</ParamField>

## Response

A successful request returns `200` with a JSON body containing the schemas for the given page.

<ResponseField name="schemas" type="object[]">
  An array of raw JSON-LD objects — one for each published schema matching the requested URL. These are the objects you can embed directly in `<script type="application/ld+json">` tags.
</ResponseField>

<ResponseField name="items" type="object[]">
  An array of full schema delivery records. Each item includes the JSON-LD object along with metadata such as the schema name, type, and status.
</ResponseField>

<ResponseField name="meta" type="object">
  <Expandable title="properties">
    <ResponseField name="version" type="string">
      The inject API version. Current value: `1.2.0`.
    </ResponseField>

    <ResponseField name="requestId" type="string">
      A unique UUID identifying this request. Use this value when reporting issues to SchemaGen support.
    </ResponseField>

    <ResponseField name="serverTime" type="string">
      ISO 8601 timestamp of when the server processed the request.
    </ResponseField>
  </Expandable>
</ResponseField>

## Response headers

| Header                 | Description                                                                                                    |
| ---------------------- | -------------------------------------------------------------------------------------------------------------- |
| `X-Schemagen-Duration` | Server-side processing time in milliseconds (e.g., `42ms`).                                                    |
| `X-Schemagen-ID`       | The unique request ID, matching `meta.requestId` in the response body.                                         |
| `Cache-Control`        | Always `no-store, max-age=0`. Responses are never cached to ensure schemas reflect the latest published state. |

## Code examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -G "https://schemagen.io/api/inject" \
    --data-urlencode "clientId=your-client-uuid" \
    --data-urlencode "url=https://example.com/blog/my-post"
  ```

  ```javascript JavaScript (fetch) theme={null}
  const params = new URLSearchParams({
    clientId: 'your-client-uuid',
    url: 'https://example.com/blog/my-post',
  });

  const response = await fetch(`https://schemagen.io/api/inject?${params}`);
  const { schemas, items, meta } = await response.json();

  // Inject schemas into the page
  for (const schema of schemas) {
    const script = document.createElement('script');
    script.type = 'application/ld+json';
    script.textContent = JSON.stringify(schema);
    document.head.appendChild(script);
  }
  ```
</CodeGroup>

## Example response

```json theme={null}
{
  "schemas": [
    {
      "@context": "https://schema.org",
      "@type": "Article",
      "headline": "How to use structured data for SEO",
      "author": {
        "@type": "Person",
        "name": "Jane Smith"
      },
      "datePublished": "2026-01-15"
    }
  ],
  "items": [
    {
      "id": "sch_01abc123",
      "name": "Blog post schema",
      "schemaType": "Article",
      "pageUrl": "https://example.com/blog/my-post",
      "status": "published",
      "jsonLd": {
        "@context": "https://schema.org",
        "@type": "Article",
        "headline": "How to use structured data for SEO",
        "author": {
          "@type": "Person",
          "name": "Jane Smith"
        },
        "datePublished": "2026-01-15"
      }
    }
  ],
  "meta": {
    "version": "1.2.0",
    "requestId": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
    "serverTime": "2026-05-08T10:30:00.000Z"
  }
}
```

## Error responses

| Status | Cause                                      | Response body                                     |
| ------ | ------------------------------------------ | ------------------------------------------------- |
| `400`  | `clientId` or `url` is missing or invalid. | `{ "error": "Validation failed", "details": {} }` |
| `500`  | An unexpected server error occurred.       | `{ "error": "Internal Server Error" }`            |

<Warning>
  If `clientId` is not a valid UUID or `url` is not an absolute URL, the API returns `400` immediately without attempting schema lookup. Double-check both values in your request.
</Warning>
