---
title: "Import document"
description: "Server-side pull: fetch a PDF from a caller-supplied URL (e.g. a presigned object-store GET) or an operator-registered storage connection into CloudPDF-owned storage, verify it, and commit it."
source: "https://www.cloudpdf.com/docs/api-reference/documents/import-from"
---

# Import document

`POST /v1/tenants/{tenantId}/documents/import` · v3.5.0

Server-side pull: fetch a PDF from a caller-supplied URL (e.g. a presigned object-store GET) or an operator-registered storage connection into CloudPDF-owned storage, verify it, and commit it.

Default mode is synchronous and bounded: the response returns only after the transfer verified and committed (or failed). mode=async (connection sources only) answers 202 immediately and an in-process worker performs the transfer with leased, fenced retries; poll the document until ready/failed. The deployment import policy gates scheme, network range, and size; sources must declare a length. CloudPDF copies and owns the bytes — the source is never referenced in place. A 502 marks a retryable upstream failure: retry with the same idempotencyKey to resume the same document. URL sources are capabilities and never echoed back. Connection sources name operator-registered storage (bucket/prefix scope, allowed credential classes, and tenant bindings are deployment configuration); \`revision\` is provider-interpreted (S3 VersionId, GCS generation, Azure version id).

## 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.

**Required scope:** `docs.create`

## Parameters

- `tenantId` string (path) — required

## Request body

`application/json` — DocumentsImportFromRequest

- `source` "url" | "connection" — required — Where CloudPDF pulls the bytes from. The two shapes differ in who supplies the authority to read, not in which storage vendor holds the file.
  - **url** — The caller supplies the authority: a presigned S3/GCS/Azure/R2/MinIO GET, or any HTTPS endpoint the deployment import policy allows. The URL is a capability — treat it as a secret. CloudPDF never echoes its query string back in errors, logs, or stored failure reasons.
    - `kind` "url" — required
    - `url` string\<uri> — required — The URL to fetch. Must be allowed by the deployment import policy (scheme, network range, size) and must declare a length.
  - **connection** — The operator pre-registered the authority: the request names a connection and a key inside it. Which provider backs the connection (S3, GCS, Azure Blob, filesystem, ...) is deployment configuration, never wire surface.
    - `kind` "connection" — required
    - `connectionId` string — required — The operator-registered storage connection to read from.
    - `key` string — required — The object key to read, inside the connection's configured scope. At most 1024 UTF-8 bytes.
    - `revision` string — Pins a specific version of the object. Provider-interpreted (S3 VersionId, GCS generation, Azure version id); providers without versioning reject it.
- `expected` object — Integrity pins, enforced when present. When absent, the server-observed values become authoritative.
  - `sizeBytes` integer — Checked against the source's declared Content-Length before the transfer.
  - `sha256` string — Checked against the server-observed digest after the transfer. Required when dedupMode is reuse-existing.
- `name` string — What people call the document: shown in dashboards, searched and sorted by. 1 to 255 characters, no control characters, no leading or trailing whitespace. Names need not be unique.
- `folderId` string — A folder id, or root for the top level.
- `metadata` object
- `idempotencyKey` string — Retrying with the same key resumes the same document rather than importing a second copy — including after a 502.
- `dedupMode` "always-create" | "reuse-existing" — always-create (default) creates a new document every time. reuse-existing returns a document that already holds the same content instead of storing it twice.
- `docId` string
- `mode` "sync" | "async" — sync (default) holds the response open for the whole transfer. async answers 202 with the document pending and transfers in the background; it requires a connection source, and filesystem connections additionally require expected.sha256.

**Example — url**

```json
{
  "source": {
    "kind": "url",
    "url": "url"
  }
}
```

**Example — connection**

```json
{
  "source": {
    "kind": "connection",
    "connectionId": "connectionId",
    "key": "key"
  }
}
```

## SDK examples

**TypeScript**

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

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

await client.documents.importFrom({
  tenantId: "tenantId",
  source: {
    kind: "url",
    url: "url"
  }
});
```

**Python**

```python
from cloudpdf import CloudPDFClient
from cloudpdf.documents import DocumentsImportFromRequestSource_Url

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

client.documents.import_from(
    tenant_id="tenantId",
    source=DocumentsImportFromRequestSource_Url(
        url="url",
    ),
)
```

**PHP**

```php
use CloudPDF\CloudPDFClient;

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

$client->documents->importFrom(
    'tenantId',
    new DocumentsImportFromRequest([
        'source' => DocumentsImportFromRequestSource::url(new DocumentsImportFromRequestSourceUrl([
            'url' => 'url',
        ])),
    ]),
);
```

**.NET**

```csharp
using CloudPDF;

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

await client.Documents.ImportFromAsync(
    new DocumentsImportFromRequest
    {
        TenantId = "tenantId",
        Source = new DocumentsImportFromRequestSource(
            new DocumentsImportFromRequestSource.Url(
                new DocumentsImportFromRequestSourceUrl { Url = "url" }
            )
        ),
    }
);
```

**Go**

```go
import (
    "context"

    cloudpdf "github.com/embedpdf/cloudpdf-sdk-go/v3"
    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 := &cloudpdf.DocumentsImportFromRequest{
    TenantID: "tenantId",
    Source: &cloudpdf.DocumentsImportFromRequestSource{
        URL: &cloudpdf.DocumentsImportFromRequestSourceURL{
            URL: "url",
        },
    },
}
client.Documents.ImportFrom(
    context.TODO(),
    request,
)
```

**Java**

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

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

client.documents().importFrom(
    "tenantId",
    DocumentsImportFromRequest
        .builder()
        .source(
            DocumentsImportFromRequestSource.url(
                DocumentsImportFromRequestSourceUrl
                    .builder()
                    .url("url")
                    .build()
            )
        )
        .build()
);
```

**Ruby**

```ruby
require "cloudpdf"

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

client.documents.import_from(tenant_id: "tenantId")
```

## Responses

### 200 — OK

`application/json` — DocumentsImportFrom200Response

- `status` "imported" | "deduped" | "accepted" — required
- `document` object — required
  - `id` string — required
  - `tenantId` string — required
  - `name` string — required
  - `folderId` string — required — The folder the document is in, or root.
  - `state` "pending" | "ready" | "failed" | "deleting" — required
  - `baseSha256` string — required
  - `sizeBytes` integer — required
  - `metadata` object — required
  - `idempotencyKey` string — required
  - `failureReason` string — required
  - `thumbnailState` "pending" | "ready" | "locked" | "failed" — required
  - `thumbnailUrl` string — required
  - `createdAt` string\<date-time> — required
  - `updatedAt` string\<date-time> — required
  - `createdBy` string — required

### 202 — Accepted

`application/json` — DocumentsImportFrom202Response

- `status` "imported" | "deduped" | "accepted" — required
- `document` object — required
  - `id` string — required
  - `tenantId` string — required
  - `name` string — required
  - `folderId` string — required — The folder the document is in, or root.
  - `state` "pending" | "ready" | "failed" | "deleting" — required
  - `baseSha256` string — required
  - `sizeBytes` integer — required
  - `metadata` object — required
  - `idempotencyKey` string — required
  - `failureReason` string — required
  - `thumbnailState` "pending" | "ready" | "locked" | "failed" — required
  - `thumbnailUrl` string — required
  - `createdAt` string\<date-time> — required
  - `updatedAt` string\<date-time> — required
  - `createdBy` string — 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.

### 403 — Forbidden

`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.

### 502 — Bad gateway

`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.
