---
title: "Delete form widget"
description: "Delete a widget: it leaves its page, and its field when it has one. The field survives, unplaced when this was its last widget. A widget that is its field's own dictionary is refused: delete the field. A widget is the form's, so the annotation routes refuse one."
source: "https://www.cloudpdf.com/docs/api-reference/document-operations/forms/delete-widget"
---

# Delete form widget

`DELETE /v1/docs/{docId}/layers/{layerName}/form/widgets/{pageKey}/{annotationKey}` · v3.5.0

Delete a widget: it leaves its page, and its field when it has one. The field survives, unplaced when this was its last widget. A widget that is its field's own dictionary is refused: delete the field. A widget is the form's, so the annotation routes refuse one.

## Authentication

Any one of these credentials is accepted.

- **apiToken** — The deployment's static root credential (CLOUDPDF\_API\_AUTH\_TOKENS), valid on every surface.
- **tenantToken** — Delegated tenant JWT, valid only for its own tenant: under /v1/tenants/\{tenantId}/ the path tenant must equal the token's tenant\_id, and on /v1/docs/\{docId} the document must belong to that tenant and the token's scope must hold the operation's document permissions, as a document token does. For servers; browsers get document tokens. Doc-scoped viewer tokens are rejected on every admin route.
- **docToken** — Doc-scoped JWT, valid only on the /v1/docs/\{docId} subtree it names, gated by the capability scopes it carries (each operation's x-required-capability).

**Document capability:** `doc.forms.modify`

## Parameters

- `docId` string (path) — required
- `layerName` string (path) — required
- `pageKey` string (path) — required
- `annotationKey` string (path) — required
- `X-Document-Password` string (header) — Base64-encoded password for an encrypted document. Valid only with the API token (403 anywhere else). An encrypted document answers 422 DocPasswordRequired when the header is absent. Viewer doc JWTs use the SDK password-session flow instead.
- `Idempotency-Key` string (header) — Names the change: 1 to 255 printable ASCII characters. A retry under the same key on the same layer answers with what the first request committed, and changes nothing.

## SDK examples

**TypeScript**

```typescript
import { CloudPDFClient } from "@cloudpdf/sdk";

const client = new CloudPDFClient({
  token: "<token>",
});

await client.doc.forms.deleteWidget({
  docId: "docId",
  layerName: "layerName",
  pageKey: "pageKey",
  annotationKey: "annotationKey"
});
```

**Python**

```python
from cloudpdf import CloudPDFClient

client = CloudPDFClient(
    token="<token>",
)

client.doc.forms.delete_widget(
    doc_id="docId",
    layer_name="layerName",
    page_key="pageKey",
    annotation_key="annotationKey",
)
```

**PHP**

```php
use CloudPDF\CloudPDFClient;

$client = new CloudPDFClient(
    token: '<token>',
);

$client->doc->forms->deleteWidget(
    'docId',
    'layerName',
    'pageKey',
    'annotationKey',
    new DeleteWidgetFormsRequest([]),
);
```

**.NET**

```csharp
using CloudPDF;

var client = new CloudPDFClient(
    "<token>"
);

await client.Doc.Forms.DeleteWidgetAsync(
    new DeleteWidgetFormsRequest
    {
        DocId = "docId",
        LayerName = "layerName",
        PageKey = "pageKey",
        AnnotationKey = "annotationKey",
    }
);
```

**Go**

```go
import (
    "context"

    client "github.com/embedpdf/cloudpdf-sdk-go/v3/client"
    option "github.com/embedpdf/cloudpdf-sdk-go/v3/option"
)

client := client.NewClient(
    option.WithToken("<token>"),
)

request := &doc.DeleteWidgetFormsRequest{
    DocID: "docId",
    LayerName: "layerName",
    PageKey: "pageKey",
    AnnotationKey: "annotationKey",
}
client.Doc.Forms.DeleteWidget(
    context.TODO(),
    request,
)
```

**Java**

```java
import com.cloudpdf.api.CloudPDFClient;

CloudPDFClient client = CloudPDFClient
    .builder()
    .token("<token>")
    .build();

client.doc().forms().deleteWidget(
    "docId",
    "layerName",
    "pageKey",
    "annotationKey",
    DeleteWidgetFormsRequest
        .builder()
        .build()
);
```

**Ruby**

```ruby
require "cloudpdf"

client = CloudPDF::Client.new(
  token: "<token>"
)

client.doc.forms.delete_widget(
  doc_id: "docId",
  layer_name: "layerName",
  page_key: "pageKey",
  annotation_key: "annotationKey"
)
```

## Responses

### 200 — OK

`application/json` — DocFormsDeleteWidgetResponse

- `widget` AnnotationRef — required
  - **objectNumber**
    - `kind` "objectNumber" — required
    - `page` PageRef — required
      - `kind` "objectNumber" — required
      - `objectNumber` integer — required
    - `objectNumber` integer — required
  - **baseIndex**
    - `kind` "baseIndex" — required
    - `page` PageRef — required
      - `kind` "objectNumber" — required
      - `objectNumber` integer — required
    - `baseIndex` integer — required
- `page` PageRef — required
  - `kind` "objectNumber" — required
  - `objectNumber` integer — required
- `field` FormField — required — A form field, by its \`family\`. A newer server can add families: read one your client doesn't know as \`unknown\`, keeping the fields every field has, with \`rawValue\` an empty string when the body has none.
- `meta` FormMutationMeta — required
  - `affectedPages` PageRef\[] — required
    - `kind` "objectNumber" — required
    - `objectNumber` integer — required
  - `cacheDelta` CacheDelta — required
  - `opId` string — required
  - `undoable` boolean — required
  - `missingCharacters` string\[]
  - `changedFields` FormFieldRef\[] — required
    - **objectNumber**
      - `kind` "objectNumber" — required
      - `objectNumber` integer — required
    - **fqn**
      - `kind` "fqn" — required
      - `name` string — required
  - `changedWidgets` FormWidget\[] — required
    - `ref` AnnotationRef — required
    - `objectNumber` integer — required
    - `page` PageRef — required
  - `redrawnWidgets` FormWidget\[] — required
    - `ref` AnnotationRef — required
    - `objectNumber` integer — required
    - `page` PageRef — required

### 400 — Bad request

`application/json` — ErrorResponse

- `error` EngineError — required
  - `code` "Unknown" | "InvalidArg" | "DocNotOpen" | "DocOpenFailed" | "DocPasswordRequired" | "DocPasswordIncorrect" | "GrantPassphraseRequired" | "Aborted" | "Network" | "Unauthenticated" | "Forbidden" | "NotFound" | "WireFormat" | "RuntimeUnavailable" | "LayerVersionConflict" | "NotImplemented" | "MalformedPdf" | "SigningPending" | "SigningExpired" | "SigningVersionMismatch" | "SignatureRefused" | "ProtectedDocument" | "PayloadTooLarge" | "ObjectNumberUnavailable" | "LayerFull" | "ChangeConflict" | "UndoUnavailable" | "IdempotencyKeyReused" | "LayerDeleted" | "VisitorIdentityRequired" | "Conflict" | "EngineBusy" | "EngineRestarting" | "DocumentQuarantined" | "ThumbnailNotReady" | "TooManyRequests" | "GrantExpired" | "OriginRequired" | "OriginNotAllowed" | "FeatureNotEnabled" | "FeatureStopped" | "LicenseInvalid" | "LicenseUsageLimit" | "UpstreamError" — required — Why the request failed. A newer server can add codes: read one your client doesn't know as \`Unknown\`.
  - `message` string — required
  - `details` object — What a code carries besides its message, as each code says.

### 404 — Not found

`application/json` — ErrorResponse

- `error` EngineError — required
  - `code` "Unknown" | "InvalidArg" | "DocNotOpen" | "DocOpenFailed" | "DocPasswordRequired" | "DocPasswordIncorrect" | "GrantPassphraseRequired" | "Aborted" | "Network" | "Unauthenticated" | "Forbidden" | "NotFound" | "WireFormat" | "RuntimeUnavailable" | "LayerVersionConflict" | "NotImplemented" | "MalformedPdf" | "SigningPending" | "SigningExpired" | "SigningVersionMismatch" | "SignatureRefused" | "ProtectedDocument" | "PayloadTooLarge" | "ObjectNumberUnavailable" | "LayerFull" | "ChangeConflict" | "UndoUnavailable" | "IdempotencyKeyReused" | "LayerDeleted" | "VisitorIdentityRequired" | "Conflict" | "EngineBusy" | "EngineRestarting" | "DocumentQuarantined" | "ThumbnailNotReady" | "TooManyRequests" | "GrantExpired" | "OriginRequired" | "OriginNotAllowed" | "FeatureNotEnabled" | "FeatureStopped" | "LicenseInvalid" | "LicenseUsageLimit" | "UpstreamError" — required — Why the request failed. A newer server can add codes: read one your client doesn't know as \`Unknown\`.
  - `message` string — required
  - `details` object — What a code carries besides its message, as each code says.

### default — Error

`application/json` — ErrorResponse

- `error` EngineError — required
  - `code` "Unknown" | "InvalidArg" | "DocNotOpen" | "DocOpenFailed" | "DocPasswordRequired" | "DocPasswordIncorrect" | "GrantPassphraseRequired" | "Aborted" | "Network" | "Unauthenticated" | "Forbidden" | "NotFound" | "WireFormat" | "RuntimeUnavailable" | "LayerVersionConflict" | "NotImplemented" | "MalformedPdf" | "SigningPending" | "SigningExpired" | "SigningVersionMismatch" | "SignatureRefused" | "ProtectedDocument" | "PayloadTooLarge" | "ObjectNumberUnavailable" | "LayerFull" | "ChangeConflict" | "UndoUnavailable" | "IdempotencyKeyReused" | "LayerDeleted" | "VisitorIdentityRequired" | "Conflict" | "EngineBusy" | "EngineRestarting" | "DocumentQuarantined" | "ThumbnailNotReady" | "TooManyRequests" | "GrantExpired" | "OriginRequired" | "OriginNotAllowed" | "FeatureNotEnabled" | "FeatureStopped" | "LicenseInvalid" | "LicenseUsageLimit" | "UpstreamError" — required — Why the request failed. A newer server can add codes: read one your client doesn't know as \`Unknown\`.
  - `message` string — required
  - `details` object — What a code carries besides its message, as each code says.
