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

# Update schedules

> Estimate and schedule extra updates for tracked posts, request an individual update, and reconcile its billing receipt.

Use update schedules to refresh tracked posts at set times or follow a new post for its first hours. You can also request one extra update for a post covered by an active schedule. Each paid update costs **USD 0.002** when the provider accepts the work. Grade settles the organization's charges daily and carries fractions of a cent forward.

Download the [OpenAPI document](https://api-docs.usegrade.com/update-schedules/openapi.json) to generate a client, or copy the [standalone TypeScript client](https://api-docs.usegrade.com/update-schedules-client.md).

## Access and operations

All paths below are relative to `/sdk/v1/update-schedules`. Send `X-Application-Id` and `X-Api-Key` on every request. Grant `scraping:read` for reads and estimates, and `scraping:write` for mutations. A client that reviews costs and then turns on a schedule needs both scopes. Only an organization admin can grant them, with the developer portal's **Post updates** preset or area. **Full access** and **Read only** leave them out.

Grade is opening update schedules to organizations gradually. Until yours has them, every call here answers `403 UPDATE_SCHEDULE_NOT_RELEASED` and the portal does not offer **Post updates**.

| Method and path | Request | Successful `data` |
| - | - | - |
| `GET /` | No body | Organization schedules, `dailyLimit`, `pricePerUpdateUsd`, engine `running` state and `billing` |
| `GET /:id` | No body | Schedule, including its current `body`, `version`, `status` and campaign scope |
| `POST /estimate` | `{checkRuleId}` for a saved schedule or `{campaignId, body}` for a draft. Either accepts an optional `dailyLimit` for this estimate. | Estimate, cost breakdown, notes and validation issues |
| `POST /` | `{campaignId, body}` | HTTP 201 with the new schedule, `OFF` at version 1 |
| `POST /:id/versions` | `{body, expectedVersion, expectedStatus, expectedDailyLimit}` | Schedule with its new active version |
| `POST /:id/status` | `{status, expectedVersion, expectedStatus}`; include `expectedDailyLimit` when turning `ON` | Schedule with its reviewed status |
| `POST /:id/updates` | `{mediaType, mediaId, expectedVersion}` | HTTP 202 with the queued update’s ID and unit price |
| `GET /:id/updates/:updateId` | No body | Dispatch and billing status of an update requested by this application |
| `PUT /daily-limit` | `{dailyLimit, expectedDailyLimit}` | Organization’s daily post-update limit and current usage |

Each success has one JSON envelope, `{ "success": true, "data": ... }`. Each mutation requires `X-Idempotency-Key`. Assign and persist a distinct key of 1–100 visible ASCII characters for each intended action before sending it. Retry an uncertain request with the same key, path and body, even after rotating the API key for the same application. Reusing that key for a changed body or another path returns `409 IDEMPOTENCY_PAYLOAD_MISMATCH`. The estimate is a read. It needs no idempotency key and never queues work.

## Estimate a schedule

Set `campaignId` to a campaign ID for a campaign schedule or to `null` for the whole organization. A schedule scoped to a campaign takes precedence over the organization’s schedule of the same kind for that campaign. Use the `/sdk/v1` base URL and credentials of your environment.

```bash theme={null}
curl --fail-with-body "$SDK_BASE_URL/update-schedules/estimate" \
  -H "X-Application-Id: $APP_ID" -H "X-Api-Key: $API_KEY" \
  -H 'Content-Type: application/json' \
  --data '{
    "campaignId": null,
    "body": {
      "schema": "check-rule/v1",
      "name": "Launch posts, twice a day",
      "when": {
        "event": "schedule", "timezone": "America/New_York",
        "times": ["09:00", "16:00"], "platforms": ["tiktok"],
        "uploaded_within_days": 14
      },
      "budget": {"monthly_usd": 25, "when_reached": "daily_check_only"}
    }
  }'
```

Review `data.issues`, `data.notes` and `data.parts` with the intended decision-maker. Each issue identifies a field by path. `perMonth.costUsd` includes the limits; `costWithoutLimitsUsd` shows the estimated demand before limits. Costs use a 30-day month. Counts or alert estimates can be `null` when unknown or inapplicable. The overview’s `billing.chargedThisMonthUsd` and `billing.notChargedYetUsd` are separate from the forecast. A `null` billing summary means those figures are unavailable.

### Rule bodies

| Field | Accepted values |
| - | - |
| `when.platforms` | A nonempty selection of distinct values from `instagram`, `tiktok`, `youtube`, `facebook`, `twitter` (X). The API normalizes the `x` alias to `twitter`. |
| `when.event: "schedule"` | An IANA `timezone` with either up to 24 distinct local `times` on the five-minute grid or `every_hours` of 1, 2, 3, 4, 6, 8 or 12. Optional `uploaded_within_days` is 1–365. |
| `when.event: "post_uploaded"` | `find_within_minutes` of 1440 uses included daily discovery. Paid discovery accepts 30–360 minutes in increments of 30. X profile discovery requires a paid interval and an enabled X integration. |
| `budget` | Positive `monthly_usd` up to 10,000 and `when_reached: "daily_check_only"`. Included daily checks continue when paid work pauses. |

For `post_uploaded`, add 1–12 `steps` in order. A `check` repeats every 5–360 minutes in increments of 5 for 1–72 whole hours. Its `on_each_check` array accepts alerts or conditions. A condition runs its `then` actions the first time a post meets the threshold. An alert uses one of the organization’s configured `slack`, `discord` or `webhook` destinations. Supply `to`, `message` and `once_per_post`. The condition below updates the post once after it reaches 50,000 views.

```json theme={null}
{
  "schema": "check-rule/v1",
  "name": "Watch the first six hours",
  "when": {"event": "post_uploaded", "platforms": ["tiktok"], "find_within_minutes": 60},
  "budget": {"monthly_usd": 25, "when_reached": "daily_check_only"},
  "steps": [{
    "type": "check", "every_minutes": 30, "for_hours": 6,
    "on_each_check": [{
      "type": "if", "metric": "views", "reaches": 50000, "compared_with": "fixed_number",
      "then": [{"type": "check_now"}]
    }]
  }]
}
```

A condition can compare views, likes, comments or shares with a positive fixed number. For example, YouTube reports no shares for these checks. A shares condition across X and YouTube applies to X posts. A YouTube-only shares condition must be changed before saving or activation. See the [typed request and response definitions](https://api-docs.usegrade.com/update-schedules-client.md) for the complete step shapes.

## Save and review changes

Save the approved draft with `POST /`. Read its current version and the organization’s `dailyLimit.limit`. Estimate the saved schedule and review its cost, monthly budget and the daily limit before turning it on. An edit to an `ON` schedule takes effect when you save the new version. Turning a schedule off stops new scheduled and on-demand updates. Updates already queued can still run. Grade bills those updates when the provider accepts them.

```typescript theme={null}
import { createUpdateSchedulesClient } from "./updateSchedules";

const schedules = createUpdateSchedulesClient({
  baseUrl: process.env.SDK_BASE_URL!,  // Includes /sdk/v1
  applicationId: process.env.SDK_APPLICATION_ID!,
  apiKey: process.env.SDK_API_KEY!,
});
const schedule = await schedules.get(scheduleId);
const { dailyLimit } = await schedules.overview();
const estimate = await schedules.estimate({ checkRuleId: schedule.id });
if (estimate.issues.length) throw new Error(estimate.issues.map(i => i.message).join("\n"));

// Run only after reviewing this version, its status, its estimated cost and this daily limit.
await schedules.setStatus(schedule.id, {
  status: "ON", expectedVersion: schedule.version, expectedStatus: schedule.status,
  expectedDailyLimit: dailyLimit.limit,
}, persistedActivationKey);
```

Use the values reviewed for this operation. Another admin can change the shared limit through a different schedule. A stale `expectedVersion`, `expectedStatus` or `expectedDailyLimit` returns `409 SCHEDULE_CHANGED`. Fetch and review the latest state before submitting a revised request with a new key. A daily limit of zero pauses paid post updates and paid discovery across the organization. The daily limit accepts whole numbers from 0 to 1,000,000. A positive daily limit covers paid post updates; paid discovery also draws on the monthly budget and wallet.

## Request one update and check its receipt

Choose a post included in the active schedule. Use `CCM` and its `campaignCreatorMediaId` for [campaign media](https://api-docs.usegrade.com/campaign-media.md) or `ATM` and its tracked media ID for [standalone tracking](https://api-docs.usegrade.com/analytics.md). Send the saved version and persist the returned `updateId`.

```typescript theme={null}
const queued = await schedules.requestUpdate(schedule.id, {
  mediaType: "CCM", mediaId: "CCMEDIA_EXAMPLE", expectedVersion: schedule.version,
}, persistedUpdateKey);
const receipt = await schedules.getUpdate(schedule.id, queued.updateId);
```

HTTP 202 confirms admission. Each key can request 100 accepted individual updates per UTC day by default. An organization admin changes that allowance in the developer portal, as the key's **Daily on-demand update limit**, to a whole number from 0 to 1,000,000; 0 pauses the key's individual updates. Rotating that key preserves its configured allowance and the day’s usage. A replay consumes no extra quota. These updates share the organization’s wallet, daily limit and schedule budget. The same application can read its receipt after rotating API keys.

| Receipt field | Meaning |
| - | - |
| `status` | `queued`, `dispatching`, `provider_accepted`, `awaiting_settlement` (dispatch ended without a provider receipt) or `settled_without_run` |
| `billing.status` | `reserved` until provider acceptance or settlement, `billable` after acceptance, then `settled` or `settled_without_charge` |
| `billing.billableUsd` | Zero until the provider accepts work, then USD 0.002. Work settled without a provider run stays at zero. |
| `billing.chargeId`, `billing.settledAt` | Daily settlement reference and timestamp when available. Several accepted updates can contribute to one wallet debit. |

The receipt tracks dispatch and billing. Read the updated numbers through [analytics](https://api-docs.usegrade.com/analytics.md) or [campaign media](https://api-docs.usegrade.com/campaign-media.md) after processing.

| HTTP | Handling |
| - | - |
| 400 | Correct the request or its idempotency key. For `INVALID_REQUEST`, `errors[]` gives a `path` and `message` for each invalid field. |
| 402 `BALANCE` | Fund the organization’s wallet before retrying the update. |
| 403 / 404 | `UPDATE_SCHEDULE_NOT_RELEASED` means Grade has not opened update schedules to the organization yet. Otherwise, check the key's scopes and the organization's access to the schedule and post. A receipt also belongs to the application that requested the update. |
| 409 | Review a stale schedule, an inactive schedule, a spending limit, a duplicate key with changed input, or an already pending update. The error code identifies the cause. |
| 429 | For a positive quota, `Retry-After` gives the seconds until capacity returns. A key set to zero stays paused until an admin changes it and omits this header. `KEY_DAILY_LIMIT` applies to the key’s UTC day; `TICK_FUSE` identifies a temporarily full paid-update queue. |
| 503 | `UPDATES_PAUSED` or `PLATFORM_UNAVAILABLE` indicates the engine or the selected provider is currently unavailable. |


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