> You are reading the Docusign Developer Documentation. For clean Markdown of any page, append .md to the page URL.
>
> Documentation indexes by section:
> - APIs and SDKs: https://docusign.docs.buildwithfern.com/docs/llms.txt
> - Platform 101: https://docusign.docs.buildwithfern.com/platform/llms.txt
> - Extension Apps: https://docusign.docs.buildwithfern.com/extension-apps/llms.txt
> - Docusign CLI: https://docusign.docs.buildwithfern.com/docusign-cli/llms.txt
>
> Authentication (OAuth, JWT Grant, M2M): https://docusign.docs.buildwithfern.com/platform/auth
> Webhooks and Connect: https://docusign.docs.buildwithfern.com/platform/webhooks
>
> OpenAPI specifications: https://docusign.docs.buildwithfern.com/openapi.json
> MCP server: https://docusign.docs.buildwithfern.com/_mcp/server

# How to add a document to Workspace

> Learn how to add a document to the Workspaces API

This topic demonstrates how to upload a document to a workspace using the Workspaces API.

> **Note**
>
> Run this code example from our [Quickstart](/docs/esign-rest-api/quickstart) or launcher projects: [Bash](https://github.com/docusign/code-examples-bash), [C#](https://github.com/docusign/code-examples-csharp), [Java](https://github.com/docusign/code-examples-java), [Node.js](https://github.com/docusign/code-examples-node), [PowerShell](https://github.com/docusign/code-examples-powershell).

## Required data

Running the code in this how-to requires this data:

| Data element            | Description                                                                                                                                                                                                                                                                                                            |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| \{API_ACCOUNT_ID}       | A [GUID](http://guid.one/) value that identifies your account. This value is automatically generated by Docusign for any account you create. Copy the value from the **API Account ID** field on the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=appsAndKeys) page.                               |
| \{WORKSPACES_BASE_PATH} | A string value that forms the root of the URL required to make API calls. The base path value in the example code is set to target the developer environment at `https://<domain>` Where `<domain>` is `https://api-d.docusign.com/v1` for the developer environment and `https://api.docusign.com/v1` for production. |
| \{WORKSPACE_ID}         | A GUID value that identifies your workspace. To return a list of your workspace IDs, use the [Workspaces: getWorkspaces](/docs/workspaces-api/reference/workspaces/workspaces/getworkspaces) method.                                                                                                                   |
| \{FILE_PATH}            | The local path to the document you want to upload.                                                                                                                                                                                                                                                                     |

## Step 1. Obtain your OAuth token

To make the API call shown in this how-to, you need a valid OAuth access token. Docusign supports access tokens for three different recommended OAuth grant types: Public Authorization Code Grant, Confidential Authorization Code Grant, and JSON Web Token (JWT) Grant. Choose the OAuth grant type appropriate for your scenario.

Wondering which grant type suits your integration? See [Authenticate](/platform/auth) for guidance on your options to get an OAuth token.

Workspaces OAuth access tokens are the same ones used for our eSignature REST API, although you must request the `signature` scope and one or more Workspaces scopes to call the Workspaces API.

> **Note**
>
> See [Workspaces authentication](/docs/workspaces-api/auth) for details and the full list of Workspaces scopes.

![Three icons that represent the three methods a user can use to obtain an OAuth token: JSON Web Token (JWT), Public Authorization Code Grant (ACG), and Confidential Authorization Code grant](/_fern-files/_img/64f473773042ee439449a096bf7673292b1585b86a4ccc55f82ba0dda41f61a1.webp)

## Step 2. Construct your API headers

After you have a valid OAuth access token, you are ready to construct the API headers that you will pass to the API call. Construct your headers like this, but make sure to substitute your valid OAuth access token for \{ACCESS_TOKEN}.

**`Bash`**

```bash title="Bash"
declare -a Headers=(
    --header "Authorization: Bearer ${ACCESS_TOKEN}"
    --header "Accept: application/json"
)
```

**`C#`**

```csharp title="C#"
var client = CreateAuthenticatedClient(accessToken);
```

**`Java`**

```java title="Java"
var accessToken = user.getAccessToken();
```

**`Node.js`**

```javascript title="Node.js"
const client = new iam.IamClient({ accessToken: args.accessToken });
```

**`PowerShell`**

```text title="PowerShell"
$boundary = [System.Guid]::NewGuid().ToString()
$headers = @{
	'Authorization' = "Bearer $accessToken";
	'Content-Type'  = "multipart/form-data; boundary=${boundary}";
}
```

## Step 3. Construct the request body for a workspace envelope draft

Next, construct a request body for a local file path and a display name for the uploaded document. Validate that the file exists before continuing.

**`Bash`**

```bash title="Bash"
while true; do
    echo ""
    echo "Enter the PDF file name (e.g. World_Wide_Corp_Web_Form.pdf) from the ${DEMO_DOCS_PATH} folder:"
    echo ""
    read file_name

    file_path="$DEMO_DOCS_PATH/$file_name"

    if [[ "$file_name" != *.pdf ]]; then
        echo ""
        echo "The file must be a PDF (must end with .pdf). Please try again."
        continue
    fi

    if [ ! -f "$file_path" ]; then
        echo ""
        echo "File not found in demo_documents folder."
        continue
    fi
    break
done

# Enter the document name for the workspace
echo ""
echo "Enter the name for the document in the workspace (must end with .pdf):"
echo ""

while true; do
  read doc_name

  doc_name=$(echo "$doc_name" | xargs)

  if [[ "$doc_name" =~ \.pdf$ ]]; then
    break
  else
    echo ""
    echo "Invalid name. The document name must end with '.pdf' (e.g., example.pdf)."
    echo "Please try again:"
  fi
done
```

**`C#`**

```csharp title="C#"
var addWorkspaceDocumentRequest = new AddWorkspaceDocumentRequest
{
    File = new AddWorkspaceDocumentRequestFile
    {
        FileName = documentName,
        Content = fileBytes,
    },
};
```

**`Java`**

```java title="Java"
var documentName = args.getDocumentName();
var documentPath = args.getDocumentPath();
```

**`Node.js`**

```javascript title="Node.js"
const buffer = await fs.readFile(args.documentPath);
const uint8array = new Uint8Array(
  buffer.buffer,
  buffer.byteOffset,
  buffer.byteLength
);
const addWorkspaceDocumentRequest = {
  file: {
    fileName: args.documentName,
    content: uint8array,
  },
};
```

**`PowerShell`**

```text title="PowerShell"
# Create a temporary copy with the desired document name
$tempFilePath = Join-Path ([System.IO.Path]::GetTempPath()) $docName
Copy-Item -Path $filePath -Destination $tempFilePath -Force

$boundary = [System.Guid]::NewGuid().ToString()
$LF = "`r`n"
$fileBytes = [System.IO.File]::ReadAllBytes($tempFilePath)
$fileContent = [System.Text.Encoding]::GetEncoding("iso-8859-1").GetString($fileBytes)

# Construct the multipart form body
$bodyLines = @(
    "--$boundary",
    "Content-Disposition: form-data; name=`"file`"; filename=`"$docName`"",
    "Content-Type: application/octet-stream$LF",
    $fileContent,
    "--$boundary",
    "Content-Disposition: form-data; name=`"name`"$LF",
    $docName,
    "--$boundary--$LF"
)
$body = $bodyLines -join $LF
```

## Step 4. Call the Workspaces API

Now that you have constructed your API headers and request body, make a POST request to the [WorkspaceDocuments: addWorkspaceDocument](/docs/workspaces-api/reference/workspaces/workspacedocuments/addworkspacedocument) endpoint and include the request body to add a workspace document. Here’s how you make the call, but make sure to substitute your API account ID for \{API_ACCOUNT_ID}, your workspaces base path for \{WORKSPACES_BASE_PATH}, and the desired workspace ID for \{WORKSPACE_ID}.

> **Note**
>
> View the source code for this how-to on GitHub: [Bash](https://github.com/docusign/code-examples-bash/blob/master/examples/Workspaces/eg002AddDocumentToWorkspace.sh), [C#](https://github.com/docusign/code-examples-csharp/blob/master/launcher-csharp/Workspaces/Examples/AddDocumentToWorkspaces.cs), [Java](https://github.com/docusign/code-examples-java/blob/master/src/main/java/com/docusign/controller/workspaces/examples/Work002AddDocumentToWorkspaceController.java), [Node.js](https://github.com/docusign/code-examples-node/blob/master/lib/workspaces/examples/addDocumentToWorkspace.js), [PowerShell](https://github.com/docusign/code-examples-powershell/blob/master/examples/Workspaces/eg002AddDocumentToWorkspace.ps1)

**`Bash`**

```bash title="Bash"
Status=$(curl -s -w "%{http_code}" -o "${response}" \
    --request POST "${base_path}/accounts/${account_id}/workspaces/${workspace_id}/documents" \
    "${Headers[@]}" \
    -F "file=@${file_path};filename=${doc_name}" \
)
```

**`C#`**

```csharp title="C#"
return await client.Workspaces.WorkspaceDocuments.AddWorkspaceDocumentAsync(
    accountId,
    workspaceId,
    addWorkspaceDocumentRequest);
```

**`Java`**

```java title="Java"
var results = AddDocumentToWorkspaceService.addDocumentToWorkspace(accessToken, accountId, workspaceId, documentPath, documentName);
```

**`Node.js`**

```javascript title="Node.js"
return await client.workspaces1.workspaceDocuments.addWorkspaceDocument({
  accountId: args.accountId,
  workspaceId: args.workspaceId,
  addWorkspaceDocumentRequest,
});
```

**`PowerShell`**

```text title="PowerShell"
$response = Invoke-WebRequest `
    -Uri "${apiUri}/accounts/${accountId}/workspaces/${workspaceId}/documents" `
    -Method 'POST' `
    -Headers $headers `
    -ContentType "multipart/form-data; boundary=$boundary" `
    -Body $body
```

## Expected response

If you run this code example from our Quickstart or launcher projects, you should see a JSON response similar to the code shown.

**`Sample response`**

```json title="Sample response"
{
 "document_id": "12345678-1234-1234-1234-abcdef123456",
 "name": "My Uploaded Document.pdf",
 "owner_id": "09876543-4321-4321-4321-fedcba654321",
 "size": 102400,
 "created_date": "2025-05-30T18:00:00Z",
 "last_updated_date": "2025-05-30T18:10:00Z"
}
```

## Next steps

* Run this code example from our [Quickstart](/docs/esign-rest-api/quickstart) or launcher projects: [Bash](https://github.com/docusign/code-examples-bash), or [PowerShell](https://github.com/docusign/code-examples-powershell).
* Learn  [How to send an envelope with recipient info](/docs/workspaces-api/how-to/send-envelope-with-recipient-information).
* Review how to [Go-Live](/platform/go-live) with your integration.