---
title: "Attach a paused ad to an existing ad group"
description: "PubNio API ads.attachAd: attach a paused ad to an existing ad group. Request fields, examples in five clients, errors, and idempotency."
---

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

# Attach a paused ad to an existing ad group

Attach a paused ad to an existing ad group with [`POST /api/v1/ads/accounts/{accountId}/ad-groups/{adGroupId}/ads`](https://pubnio.com/api/v1/docs#tag/ads/POST/api/v1/ads/accounts/{accountId}/ad-groups/{adGroupId}/ads). Requires an API key with the `ads_manage` scope or a signed-in workspace member.

## Request

Owner, member, or ads_manage key. Creates a paused ad under an existing PubNio-managed ad group. Separate-creative providers require a stored creativeId; embedded-creative providers require creative fields. The provider call reads the ad back before the operation succeeds.

| Parameter     | In    | Type | Required |
| ------------- | ----- | ---- | -------- |
| `accountId`   | path  | UUID | Yes      |
| `adGroupId`   | path  | UUID | Yes      |
| `workspaceId` | query | UUID | Yes      |

| Body field         | Type               | Required |
| ------------------ | ------------------ | -------- |
| `name`             | string             | Yes      |
| `creativeId`       | UUID               | No       |
| `creative`         | AdAttachAdCreative | No       |
| `providerSettings` | object             | No       |

## Response

- HTTP 202: `AdOperation` with `id`, `accountId`, `kind`, `status`, `step`, `input`, `result`, `issues`, `attempts`, `canRetry`, `nextAction`, `createdAt`, `updatedAt`, `startedAt`, `completedAt`.
  - `kind`: `boost.create`, `campaign.create`, `campaign.activate`, `campaign.pause`, `campaign.archive`, `ad_group.status`, `ad_group.create`, `ad.status`, `ad.attach`, `creative.create`, `campaign.duplicate`, `budget.update`
  - `status`: `queued`, `preflight`, `creating`, `recording`, `reviewing`, `activating`, `succeeded`, `partial`, `failed`, `unresolved`, `cancelled`
  - `step`: `queued`, `preflight`, `create`, `record`, `review`, `activate`, `finish`

The [OpenAPI document](https://pubnio.com/api/v1/openapi) has each field's type.

## Examples

### TypeScript

```ts
const operation = await workspace.ads.attachAd(accountId, adGroupId, {
  name: "Spring sale ad",
  creativeId,
});
```

### Python

```python
operation = workspace.ads.attach_ad(
    account_id,
    ad_group_id,
    name="Spring sale ad",
    creative_id=creative_id,
)
```

### cURL

```sh
curl -X POST "https://pubnio.com/api/v1/ads/accounts/$ACCOUNT_ID/ad-groups/$AD_GROUP_ID/ads?workspaceId=$WORKSPACE_ID" \
  -H "Authorization: Bearer $PUBNIO_API_KEY" \
  -H "Idempotency-Key: $IDEMPOTENCY_KEY" \
  -H "Content-Type: application/json" \
  -d '{"name":"Spring sale ad","creativeId":"'"$CREATIVE_ID"'"}'
```

### CLI

```sh
pnio ads attach-ad "$ACCOUNT_ID" "$AD_GROUP_ID" --name "Spring sale ad" --creative-id "$CREATIVE_ID"
```

### MCP execute

```js
async () => {
  const accountId = "<accountId>";
  const adGroupId = "<adGroupId>";
  const creativeId = "<creativeId>";
  // 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/accounts/${accountId}/ad-groups/${adGroupId}/ads`,
    query: { workspaceId: codemode.workspaceId },
    headers: { "Idempotency-Key": idempotencyKey },
    body: { name: "Spring sale ad", creativeId: creativeId },
  });
  return response.data;
};
```

## Errors

It declares no problem of its own.

It declares the problems [every Ads operation](https://pubnio.com/docs/reference/#ads) and [most operations](https://pubnio.com/docs/reference/#shared-problems) 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](https://pubnio.com/docs/concepts/idempotency/).

## Limits

- Field lengths and ranges are in the [OpenAPI document](https://pubnio.com/api/v1/openapi).

## Related

- [Ads operations](https://pubnio.com/docs/reference/#ads)

Source: https://pubnio.com/docs/reference/ads-attach-ad/index.mdx
