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

# Automating content creation with The Prompting Company’s API

> Upload a Markdown file, approve its draft, and verify that the page is live.

Use the Content API to publish Markdown from your CMS, docs repository, or build pipeline. This guide takes a local `install.md` file through draft creation, approval, and publication.

## Before you start

* Create an [organization API key](https://docs.promptingcompany.com/api/authentication.md#api-key) with `content:write` for creating and approving drafts and `content:read` for checking publication. An owner or admin can grant the write scope on an active or trialing Enterprise plan. Set `TPC_API_KEY` in your environment or inject it from your CI secret store.
* Set `TPC_PRODUCT_ID` to the ID of a product in that organization. Use a product with a [connected publishing domain](https://docs.promptingcompany.com/guides/create-content.md#set-up-custom-domain).
* Install `curl` and `jq`, and save the Markdown you want to publish as `install.md`.

## 1. Upload the Markdown

[Create content](https://docs.promptingcompany.com/api/reference/content/create-content.md) accepts the file contents as a JSON string. Choose a new path for the page. In the examples below, set `PUBLISH_RUN_ID` to an identifier for this submission. Reuse it when retrying the same requests and use a new one when the payload changes. [Read about idempotency](https://docs.promptingcompany.com/api/idempotency.md).

```bash theme={null}
API_BASE="https://app.promptingco.com/api/v1"
PAGE_PATH="docs/install"
PUBLISH_RUN_ID="install-guide-v1"

CREATE_BODY=$(jq -n \
  --arg productId "$TPC_PRODUCT_ID" \
  --arg slug "$PAGE_PATH" \
  --rawfile content install.md \
  '{productId: $productId, pages: [{slug: $slug, title: "Install guide", content: $content}]}')

CREATE_RESULT=$(curl --silent --show-error --fail-with-body "$API_BASE/content" \
  -X POST \
  -H "content-type: application/json" \
  -H "x-api-key: $TPC_API_KEY" \
  -H "Idempotency-Key: $PUBLISH_RUN_ID-create" \
  --data-binary @- <<< "$CREATE_BODY")

printf '%s\n' "$CREATE_RESULT" | jq '.data | {createdCount, failedCount, created, failed}'
DRAFT_ID=$(printf '%s\n' "$CREATE_RESULT" | jq -er \
  'select(.ok == true and .data.failedCount == 0) | .data.created[0].id')
```

Continue only after you have a draft ID. The page should be in `pending_review`, with `sourceUrl: null`. The endpoint accepts up to 25 pages per request. A batch can return `ok: true` with per-page failures, so check `failedCount` and `failed` and retain the IDs of successful drafts.

The product's default publishing domains apply unless you pass a product custom domain ID as `canonicalDomainId` in the page object.

## 2. Approve the draft

After you've reviewed the draft, send its ID to [Review a content draft](https://docs.promptingcompany.com/api/reference/content/review-a-content-draft.md).

```bash theme={null}
curl --silent --show-error --fail-with-body "$API_BASE/content/$DRAFT_ID/review" \
  -X POST \
  -H "content-type: application/json" \
  -H "x-api-key: $TPC_API_KEY" \
  -H "Idempotency-Key: $PUBLISH_RUN_ID-approve" \
  --data '{"action":"approve"}'
```

A successful approval for the Markdown page returns:

```json theme={null}
{
  "ok": true,
  "data": {
    "draftId": "adraft_123",
    "action": "approve",
    "queuedForPublish": true
  }
}
```

`queuedForPublish: true` means the publishing job was queued. Continue to the next step to check whether it finished. A draft for an external platform can be approved with `queuedForPublish: false` and must be published through that platform.

Use [Publish an approved content draft](https://docs.promptingcompany.com/api/reference/content/publish-an-approved-content-draft.md) to requeue an approved site draft if its publishing job failed and the page is still unpublished.

## 3. Verify publication

Call [Get content](https://docs.promptingcompany.com/api/reference/content/get-content.md) with the draft ID. Its `documentId` is empty until publishing creates or updates the live document. Once you have that ID, use the same endpoint to get the document status and URL.

```bash theme={null}
DRAFT_RESULT=$(curl --silent --show-error --fail-with-body "$API_BASE/content/$DRAFT_ID" \
  -H "x-api-key: $TPC_API_KEY")
DOCUMENT_ID=$(printf '%s\n' "$DRAFT_RESULT" | jq -r '.data.documentId // empty')

if [ -n "$DOCUMENT_ID" ]; then
  DOCUMENT_RESULT=$(curl --silent --show-error --fail-with-body "$API_BASE/content/$DOCUMENT_ID" \
    -H "x-api-key: $TPC_API_KEY") &&
    printf '%s\n' "$DOCUMENT_RESULT" | jq \
      '.data | select(.kind == "document" and .status == "published") | {id, filePath, status, sourceUrl}'
fi
```

Once publishing finishes, you should see a result like this:

```json theme={null}
{
  "id": "document_456",
  "filePath": "docs/install",
  "status": "published",
  "sourceUrl": "https://docs.example.com/docs/install"
}
```

If the command prints no result, wait and run the lookup again. In automation, poll with a time limit. If the page still doesn't appear, check the draft and publishing domain in the dashboard. Open the returned URL to confirm that the page serves the expected content.

For subsequent edits, use the document ID with [Update a document](https://docs.promptingcompany.com/api/content/documents.md#update-a-document). Keep the draft ID for actions on the review queue.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.