Skip to content

Create a paused campaign plan

PubNio API ads.createCampaignPlan: create a paused campaign plan. Request fields, examples in five clients, errors, and idempotency.

Create a paused campaign plan with POST /api/v1/ads/campaigns. Requires an API key with the ads_manage scope or a signed-in workspace member.

Request

Validates one workspace plan, then creates one paused campaign per target account. Returns one operation per target. The same Idempotency-Key and intent return the same plan; a different intent returns 409. Spend is not activated by this call.

Parameter In Type Required
workspaceId query UUID Yes
Body field Type Required
name string Yes
objective one of 10 strings Yes
budget AdBudget No
schedule AdSchedule No
targets array of AdCampaignPlanTarget Yes
adGroups array of AdCampaignPlanAdGroup Yes
providerSettings object No

Response

  • HTTP 202: AdCampaignPlanAccepted with planId, status, targets.
    • status: queued, creating, partial, succeeded, failed, unresolved

The OpenAPI document has each field’s type.

Examples

const accepted = await workspace.ads.createCampaignPlan({
  name: "Spring sale",
  objective: "traffic",
  targets: [{ accountId }],
  adGroups: [
    {
      name: "Returning visitors",
      ads: [{ name: "Spring sale ad", creative: { headline: "Spring sale" } }],
    },
  ],
});
accepted = workspace.ads.create_campaign_plan(
    name="Spring sale",
    objective="traffic",
    targets=[{"accountId": account_id}],
    ad_groups=[
        {
            "name": "Returning visitors",
            "ads": [
                {
                    "name": "Spring sale ad",
                    "creative": {
                        "headline": "Spring sale",
                        "destinationUrl": "https://example.com/spring",
                    },
                },
            ],
        },
    ],
)
curl -X POST "https://pubnio.com/api/v1/ads/campaigns?workspaceId=$WORKSPACE_ID" \
  -H "Authorization: Bearer $PUBNIO_API_KEY" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"Spring sale","objective":"traffic","targets":[{"accountId":"'"$ACCOUNT_ID"'"}],"adGroups":[{"name":"Returning visitors","ads":[{"name":"Spring sale ad","creative":{"headline":"Spring sale","destinationUrl":"https://example.com/spring"}}]}]}'
pnio ads create-campaign-plan --file campaign-plan.json
async () => {
  const accountId = "<accountId>";
  // One key per intent; reuse it only to retry this same request.
  const idempotencyKey = crypto.randomUUID();
  const response = await codemode.request({
    method: "POST",
    path: "/api/v1/ads/campaigns",
    query: { workspaceId: codemode.workspaceId },
    headers: { "Idempotency-Key": idempotencyKey },
    body: {
      name: "Spring sale",
      objective: "traffic",
      targets: [{ accountId: accountId }],
      adGroups: [
        {
          name: "Returning visitors",
          ads: [
            {
              name: "Spring sale ad",
              creative: {
                headline: "Spring sale",
                destinationUrl: "https://example.com/spring",
              },
            },
          ],
        },
      ],
    },
  });
  return response.data;
};

Errors

It declares no problem of its own.

It declares the problems every Ads operation and most operations declare.

Idempotency

Required. A retry with the same Idempotency-Key returns the first result for 24 hours. Make one key per intent, such as crypto.randomUUID() or Python’s uuid4(), and reuse it only to retry the same request. The TypeScript SDK makes a key for each call unless you pass idempotencyKey. See Idempotency.

Limits

Type to search…

↑↓ navigate↵ selectEsc close