> For the complete documentation index, see [llms.txt](https://docs.shadowcipher.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.shadowcipher.in/endpoints/fetch-document.md).

# Fetch a document

Get a transaction's PDF as base64 — the signed copy once signed, otherwise the original.

<mark style="color:blue;">`POST`</mark> `/api/oauth/fetchDoc`

Returns the PDF for a transaction. Once the document is signed you get the signed copy; before that you get the original.

## Headers

| Header          | Value                   |
| --------------- | ----------------------- |
| `Authorization` | `Bearer <access_token>` |
| `Content-Type`  | `application/json`      |

## Request body

| Field    | Type   | Required | Description                                                                                                             |
| -------- | ------ | -------- | ----------------------------------------------------------------------------------------------------------------------- |
| `txn_no` | string | Yes      | The `txn_no` returned by [Start a signing transaction](https://docs.shadowcipher.in/endpoints/initiate-transaction.md). |

## Example

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST https://app.shadowcipher.in/api/oauth/fetchDoc \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"txn_no":"3f2c1a9e8b7d4c6a9e1f0b2d3c4a5e6f"}' \
  | jq -r .document | base64 --decode > signed.pdf
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
import { writeFile } from "node:fs/promises";

const res = await fetch("https://app.shadowcipher.in/api/oauth/fetchDoc", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${accessToken}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ txn_no }),
});
const doc = await res.json();
if (doc.status === "SIGNED") {
  await writeFile(doc.file_name, Buffer.from(doc.document, "base64"));
}
```

{% endtab %}
{% endtabs %}

## Responses

{% tabs %}
{% tab title="200 OK" %}

```json
{
  "txn_no": "3f2c1a9e8b7d4c6a9e1f0b2d3c4a5e6f",
  "reference_no": "INV-2026-0042",
  "status": "SIGNED",
  "file_type": "PDF",
  "file_name": "INV-2026-0042.pdf",
  "document": "JVBERi0xLjcK..."
}
```

| Field          | Type   | Description                                                                        |
| -------------- | ------ | ---------------------------------------------------------------------------------- |
| `txn_no`       | string | Transaction number.                                                                |
| `reference_no` | string | Your reference.                                                                    |
| `status`       | string | `SIGNED`: `document` is the signed PDF. `INITIATED`: the original, not yet signed. |
| `file_type`    | string | `PDF`                                                                              |
| `file_name`    | string | Suggested download name (`<reference_no>.pdf`).                                    |
| `document`     | string | The PDF, base64-encoded.                                                           |
| {% endtab %}   |        |                                                                                    |

{% tab title="400" %}
`txn_no` is missing or the body isn't JSON.
{% endtab %}

{% tab title="401" %}
Missing, invalid or expired access token.
{% endtab %}

{% tab title="403" %}
The token lacks the `txn:initiate` scope or the client is inactive.
{% endtab %}

{% tab title="404" %}
No such transaction for this client, or its document file is missing.
{% endtab %}

{% tab title="429" %}
Rate limit exceeded. See [Rate limits](https://docs.shadowcipher.in/reference/rate-limits.md).
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.shadowcipher.in/endpoints/fetch-document.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
