> 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 forms to a room

> Learn how to attach and add forms to a room with the Rooms API

Docusign Rooms for Real Estate only

This topic demonstrates how to attach forms to a room using the Rooms 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), [PHP](https://github.com/docusign/code-examples-php), [PowerShell](https://github.com/docusign/code-examples-powershell), [Python](https://github.com/docusign/code-examples-python), or [Ruby](https://github.com/docusign/code-examples-ruby).

## 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.                      |
| \{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>/restapi/v2 Where \<domain> is demo.rooms.docusign.com for the developer environment and rooms.docusign.com for production. |
| \{FORM_ID}                          | A [GUID](http://guid.one/) value that identifies the form to attach to a room. To return a list of your form IDs, use the [FormLibraries:GetFormLibraries](/docs/rooms-api/reference/forms/formlibraries/getformlibraries) method.                                                                            |
| Forms enabled on your Rooms account | The user role needs the **AddDocumentsFromFormGroupToRooms** or **AddDocumentsFromFormLibrariesToRooms** permission assigned. These permissions are only available to accounts with Forms enabled. To enable this feature, contact your Account Manager or Business Development representative.               |
| \{ROOM_ID}                          | A unique integer that identifies your room. To return a list of your room IDs, use the [Rooms:GetRooms](/docs/rooms-api/reference/rooms/rooms/getrooms) method.                                                                                                                                               |
| Rooms enabled for your account      | You will need access enabled to use the Rooms API. See [creating a Rooms developer account](/docs/rooms-api/rooms101/create-account).                                                                                                                                                                         |

## Step 1. Obtain your OAuth token

To make the API call shown in this how-to, you need a valid OAuth access token with the `dtr.rooms.write` scope enabled. 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.

> **Note**
>
> See [Authentication](/docs/rooms-api/rooms101/auth) for guidance on your options to get an OAuth token.

![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"
    '--header' "Content-Type: application/json")
```

**`C#`**

```csharp title="C#"
var apiClient = new DocuSignClient(basePath);
apiClient.Configuration.DefaultHeader.Add("Authorization", $"Bearer {accessToken}");
var roomsApi = new RoomsApi(apiClient);
var formLibrariesApi = new FormLibrariesApi(apiClient);
```

**`Java`**

```java title="Java"
RoomsApi roomsApi = createRoomsApiClient(this.session.getBasePath(), this.user.getAccessToken());
```

**`Node.js`**

```javascript title="Node.js"
let dsApiClient = new docusignRooms.ApiClient();
dsApiClient.setBasePath(args.basePath);
dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken);
```

**`PHP`**

```php title="PHP"
$config = new Configuration();
$config->setHost('https://demo.rooms.docusign.com/restapi');
$config->addDefaultHeader('Authorization', 'Bearer ' . $args['ds_access_token']);
$this->apiClient = new ApiClient($config);
```

**`PowerShell`**

```text title="PowerShell"
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.add("Authorization", "Bearer $accessToken")
$headers.add("Accept", "application/json")
$headers.add("Content-Type", "application/json")
```

**`Python`**

```python title="Python"
api_client = create_rooms_api_client(access_token=args["access_token"])
(form_library_forms, status, headers) = form_libraries_api.get_form_library_forms_with_http_info(
    form_library_id=first_form_library_id,
    account_id=args["account_id"]
)

remaining = headers.get("X-RateLimit-Remaining")
reset = headers.get("X-RateLimit-Reset")

if remaining is not None and reset is not None:
    reset_date = dt.fromtimestamp(int(reset), tz=timezone.utc)
    print(f"API calls remaining: {remaining}")
    print(f"Next Reset: {reset_date}")
```

**`Ruby`**

```ruby title="Ruby"
configuration = DocuSign_Rooms::Configuration.new
configuration.host = Rails.configuration.rooms_host

api_client = DocuSign_Rooms::ApiClient.new(configuration)
api_client.set_default_header('Authorization', "Bearer #{args[:access_token]}")
```

## Step 3. Obtain the desired form ID

Rooms accounts have forms bundled into objects known as  [FormLibraries](/docs/rooms-api/reference/forms/formlibraries).

**Note:** Your account needs to have access to documents and forms data; otherwise, you will be unable to retrieve a form ID from the `FormLibraries` resource.

Retrieve your intended form ID from the `libraryFormId`.  Here’s how you make the call, but make sure to substitute your API account ID for \{ACCOUNT_ID}

**`Bash`**

```bash title="Bash"
printf \
    '{
        "formId":"'"$library_form_id"'",
    }' >$request_data
```

**`C#`**

```csharp title="C#"
ApiResponse<FormLibrarySummaryList> formLibraries = formLibrariesApi.GetFormLibrariesWithHttpInfo(accountId);

formLibraries.Headers.TryGetValue("X-RateLimit-Remaining", out string remaining);
formLibraries.Headers.TryGetValue("X-RateLimit-Reset", out string reset);

if (reset != null && remaining != null)
{
    DateTime resetDate = DateTimeOffset.FromUnixTimeSeconds(long.Parse(reset)).UtcDateTime;
    Console.WriteLine("API calls remaining: " + remaining);
    Console.WriteLine("Next Reset: " + resetDate);
}

// Get Forms
ApiResponse<FormSummaryList> forms = null;
if (formLibraries.Data.FormsLibrarySummaries.Any())
{
    forms = formLibrariesApi.GetFormLibraryFormsWithHttpInfo(
        accountId,
        formLibraries.Data.FormsLibrarySummaries.First().FormsLibraryId);
}

forms.Headers.TryGetValue("X-RateLimit-Remaining", out remaining);
forms.Headers.TryGetValue("X-RateLimit-Reset", out reset);

if (reset != null && remaining != null)
{
    DateTime resetDate = DateTimeOffset.FromUnixTimeSeconds(long.Parse(reset)).UtcDateTime;
    Console.WriteLine("API calls remaining: " + remaining);
    Console.WriteLine("Next Reset: " + resetDate);
}
```

**`Java`**

```java title="Java"
GetRoomsOptions gro = roomsApi.new GetRoomsOptions();
gro.setCount(5);
RoomSummaryList roomSummaryList = roomsApi.getRooms(this.session.getAccountId(), gro);

List<FormSummary> forms = GetFormSummaryListService.getFormSummaryList(
        createFormLibrariesApi(session.getBasePath(), this.user.getAccessToken()),
        this.session.getAccountId());
```

**`Node.js`**

```javascript title="Node.js"
let formLibrariesApi = new docusignRooms.FormLibrariesApi(dsApiClient);
let formLibrariesResults = null;

formLibrariesResults = await new Promise((resolve, reject) => {
    formLibrariesApi.getFormLibraries(
    args.accountId,
      (err, data, response) => {
      if (err) return reject(err);
      resolve({ data, response });
    });
  });

  headers = formLibrariesResults.response.headers;
  remaining = headers['x-ratelimit-remaining'];
  reset = headers['x-ratelimit-reset'];

  if (remaining && reset) {
    const resetInstant = new Date(Number(reset) * 1000);
    console.log(`API calls remaining: ${remaining}`);
    console.log(`Next Reset: ${resetInstant.toISOString()}`);
  }

if (formLibrariesResults.data.formsLibrarySummaries.length === 0) {
  return;
}

const firstFormLibraryId = formLibrariesResults.data.formsLibrarySummaries.find(
  (lib) => lib.formCount > 0
).formsLibraryId;
  formsResults = await new Promise((resolve, reject) => {
    formLibrariesApi.getFormLibraryForms(
      args.accountId,
      firstFormLibraryId,
      (err, data, response) => {
      if (err) return reject(err);
      resolve({ data, response });
    });
  });

  headers = formsResults.response.headers;
  remaining = headers['x-ratelimit-remaining'];
  reset = headers['x-ratelimit-reset'];

  if (remaining && reset) {
    const resetInstant = new Date(Number(reset) * 1000);
    console.log(`API calls remaining: ${remaining}`);
    console.log(`Next Reset: ${resetInstant.toISOString()}`);
  }
var formsResultsList = formsResults.data;
```

**`PHP`**

```php title="PHP"
$form_libraries_api = $this->getFormLibrariesApi();
try {
    $form_libraries = $form_libraries_api->getFormLibrariesWithHttpInfo($args['account_id']);

    $remaining = $response[2]['x-ratelimit-remaining'] ?? null;
    $reset = $response[2]['x-ratelimit-reset'] ?? null;

    if ($remaining !== null && $reset !== null) {
        $resetInstant = (new DateTime())->setTimestamp((int)$reset);
        error_log("API calls remaining: $remaining");
        error_log("Next Reset: " . $resetInstant->format(\DateTime::ATOM));
    }
} catch (ApiException $e) {
    $this->showErrorTemplate($e);
    exit;
}
    public function getFormLibrariesApi(): FormLibrariesApi
    {
return new FormLibrariesApi($this->apiClient);
    }
$form_libraries_api = $this->getFormLibrariesApi();
try {
    $forms = $form_libraries_api->getFormLibraryFormsWithHttpInfo($forms_library_id, $account_id);

    $remaining = $response[2]['x-ratelimit-remaining'] ?? null;
    $reset = $response[2]['x-ratelimit-reset'] ?? null;

    if ($remaining !== null && $reset !== null) {
        $resetInstant = (new DateTime())->setTimestamp((int)$reset);
        error_log("API calls remaining: $remaining");
        error_log("Next Reset: " . $resetInstant->format(\DateTime::ATOM));
    }
} catch (ApiException $e) {
    $this->showErrorTemplate($e);
    exit;
}
```

**`PowerShell`**

```text title="PowerShell"
$uri = "https://demo.rooms.docusign.com/restapi/v2/accounts/$APIAccountId/form_libraries"
$response = Invoke-WebRequest -uri $uri -UseBasicParsing -headers $headers
$formLibraryId = $($response.Content | ConvertFrom-Json).formsLibrarySummaries[0].formsLibraryId

# Get Form ID
$uri = "https://demo.rooms.docusign.com/restapi/v2/accounts/$APIAccountId/form_libraries/$formLibraryId/forms"
$response = Invoke-WebRequest -uri $uri -UseBasicParsing -headers $headers -method GET
$formId = $($response.Content | ConvertFrom-Json).forms[0].libraryFormId

# Construct the request body for adding a form
$body = @"
{"formId":"$formId"}
"@
```

**`Python`**

```python title="Python"
form_libraries_api = FormLibrariesApi(api_client)
(form_libraries, status, headers) = form_libraries_api.get_form_libraries_with_http_info(account_id=args["account_id"])

remaining = headers.get("X-RateLimit-Remaining")
reset = headers.get("X-RateLimit-Reset")

if remaining is not None and reset is not None:
    reset_date = dt.fromtimestamp(int(reset), tz=timezone.utc)
    print(f"API calls remaining: {remaining}")
    print(f"Next Reset: {reset_date}")

first_form_library_id = form_libraries.forms_library_summaries[10].forms_library_id
```

**`Ruby`**

```ruby title="Ruby"
DocuSign_Rooms::FormForAdd.new({
                                 formId: form_id
                               })
```

## Step 4. Call the Rooms API

Now that you have a form ID, make a POST request to the [Rooms:AddFormToRoom](/docs/rooms-api/reference/rooms/rooms/addformtoroom) endpoint to attach the form to your room by specifying the aforementioned form ID in the request body.

**Note:** When adding forms to rooms, each form ID must be unique or the form will fail to be added.

**`Bash`**

```bash title="Bash"
Status=$(curl -w '%{http_code}' -i --request POST "https://demo.rooms.docusign.com/restapi/v2/accounts/${account_id}/rooms/${room_id}/forms" \
    "${Headers[@]}" \
    --data-binary @${request_data} \
    --output ${response})
```

**`C#`**

```csharp title="C#"
var response = roomsApi.AddFormToRoomWithHttpInfo(accountId, roomId, new FormForAdd(formId));
response.Headers.TryGetValue("X-RateLimit-Remaining", out string remaining);
response.Headers.TryGetValue("X-RateLimit-Reset", out string reset);

if (reset != null && remaining != null)
{
    DateTime resetDate = DateTimeOffset.FromUnixTimeSeconds(long.Parse(reset)).UtcDateTime;
    Console.WriteLine("API calls remaining: " + remaining);
    Console.WriteLine("Next Reset: " + resetDate);
}

return response.Data;
```

**`Java`**

```java title="Java"
RoomDocument roomDocument = AddingFormsToRoomService.addFormsToRoom(
        roomsApi,
        this.session.getAccountId(),
        args.getFormId(),
        args.getRoomId());
```

**`Node.js`**

```javascript title="Node.js"
let roomsApi = new docusignRooms.RoomsApi(dsApiClient);
  let results = null;

  results = await new Promise((resolve, reject) => {
    roomsApi.addFormToRoom(
      args.accountId,
      args.roomsArgs.roomId,
      { body: { formId: args.roomsArgs.libraryFormId } },
      null,
      (err, data, response) => {
      if (err) return reject(err);
      resolve({ data, response });
    });
  });

  headers = results.response.headers;
  remaining = headers['x-ratelimit-remaining'];
  reset = headers['x-ratelimit-reset'];

  if (remaining && reset) {
    const resetInstant = new Date(Number(reset) * 1000);
    console.log(`API calls remaining: ${remaining}`);
    console.log(`Next Reset: ${resetInstant.toISOString()}`);
  }
```

**`PHP`**

```php title="PHP"
$form_for_add = new FormForAdd($args);
$response = $rooms_api->addFormToRoomWithHttpInfo($args['room_id'], $args["account_id"], $form_for_add);

$remaining = $response[2]['x-ratelimit-remaining'] ?? null;
$reset = $response[2]['x-ratelimit-reset'] ?? null;

if ($remaining !== null && $reset !== null) {
    $resetInstant = (new DateTime())->setTimestamp((int)$reset);
    error_log("API calls remaining: $remaining");
    error_log("Next Reset: " . $resetInstant->format(\DateTime::ATOM));
}
```

**`PowerShell`**

```text title="PowerShell"
$uri = "https://demo.rooms.docusign.com/restapi/v2/accounts/$APIAccountId/rooms/$roomId/forms"

try {
  # Display the JSON response
  Write-Output "Response:"
  $response = Invoke-WebRequest -uri $uri -UseBasicParsing -headers $headers -body $body -method POST
  $response.Content | ConvertFrom-Json | ConvertTo-Json
}
catch {
  Write-Output "Unable to add the new form."
  # On failure, display a notification, X-DocuSign-TraceToken, error message, and the command that triggered the error
  foreach ($header in $_.Exception.Response.Headers) {
    if ($header -eq "X-DocuSign-TraceToken") { Write-Output "TraceToken : " $_.Exception.Response.Headers[$int] }
    $int++
  }
  Write-Output "Error : "$_.ErrorDetails.Message
  Write-Output "Command : "$_.InvocationInfo.Line
}
```

**`Python`**

```python title="Python"
rooms_api = RoomsApi(api_client)
(response, status, headers) = rooms_api.add_form_to_room_with_http_info(
    room_id=args['room_id'],
    body=FormForAdd(form_id=args['form_id']),
    account_id=args["account_id"]
)

remaining = headers.get("X-RateLimit-Remaining")
reset = headers.get("X-RateLimit-Reset")

if remaining is not None and reset is not None:
    reset_date = dt.fromtimestamp(int(reset), tz=timezone.utc)
    print(f"API calls remaining: {remaining}")
    print(f"Next Reset: {reset_date}")
```

**`Ruby`**

```ruby title="Ruby"
rooms_api = DocuSign_Rooms::RoomsApi.new(api_client)

results, _status, headers = rooms_api.add_form_to_room_with_http_info(args[:room_id], args[:account_id], body(args[:form_id]))

remaining = headers['X-RateLimit-Remaining']
reset = headers['X-RateLimit-Reset']

if remaining && reset
  reset_date = Time.at(reset.to_i).utc
  puts "API calls remaining: #{remaining}"
  puts "Next Reset: #{reset_date}"
end
```

## Expected response

If your API call is successful, you should see a JSON response similar to this.

> **Note**
>
> View the source code for this how-to on GitHub: [Bash](https://github.com/docusign/code-examples-bash/blob/master/examples/Rooms/eg004AddFormsToRoomController.sh), [C#](https://github.com/docusign/code-examples-csharp/blob/master/launcher-csharp/Rooms/Examples/AddingFormToRoom.cs),  [Java](https://github.com/docusign/code-examples-java/blob/master/src/main/java/com/docusign/controller/rooms/services/AddingFormsToRoomService.java), [Node](https://github.com/docusign/code-examples-node/blob/master/lib/rooms/examples/addingFormToRoom.js), [PHP](https://github.com/docusign/code-examples-php/blob/master/src/Services/Examples/Rooms/AddFormsToRoomService.php), [PowerShell](https://github.com/docusign/code-examples-powershell/blob/master/examples/Rooms/eg004AddFormsToRoomController.ps1), [Python](https://github.com/docusign/code-examples-python/blob/master/app/rooms/examples/eg004_add_forms_to_room.py), or [Ruby](https://github.com/docusign/code-examples-ruby/blob/main/app/services/room_api/eg004_add_forms_to_room_service.rb).

**`Sample response`**

```json title="Sample response"
{
  "documentId": 3xxxx4,
  "name": "LREC - Residential Purchase Agreement.pdf",
  "ownerId": 2xxxx4,
  "size": 0,
  "createdDate": "2020-08-06T20:46:06.973",
  "isSigned": false,
  "docuSignFormId": "6ab833df-xxxx-xxxx-xxxx-9576243ca995",
  "isArchived": false
}
```

## 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), [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), [PHP](https://github.com/docusign/code-examples-php), [PowerShell](https://github.com/docusign/code-examples-powershell), [Python](https://github.com/docusign/code-examples-python), or [Ruby](https://github.com/docusign/code-examples-ruby).
* See [How to create a room with data](/docs/rooms-api/how-to/create-room-with-data).
* See [How to create a room with a template](/docs/rooms-api/how-to/create-room-with-template).
* Learn more about [Using room templates and task lists](/docs/rooms-api/rooms101/templates).
* See how to [Go-Live](/docs/rooms-api/go-live)  with a completed app and find the base path for API calls in the production environment.