> 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 grant office access to a form group

> This topic demonstrates how to assign an office to a form group for your Docusign Rooms for Real Estate account. As a prerequisite, make sure that you have created a form group.

Docusign Rooms for Real Estate only

This topic demonstrates how to assign an office to a [form group](/docs/rooms-api/rooms101/forms/managing-forms-rooms) for your Docusign Rooms for Real Estate account. As a prerequisite, make sure that you have [created a form group](/docs/rooms-api/how-to/create-form-group). Assigning an office to a form group associates that group with that office, granting the group access to the office. Granting office access to a form group will enable you to filter which form groups are available based on that office.

> **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_GROUP_ID}                    | A [GUID](http://guid.one/) value that identifies your form group. This value is created by Docusign when you [create a form group](/docs/rooms-api/how-to/create-form-group).                                                                                                                                 |
| Forms enabled on your Rooms account | The user role needs the **Manage form groups** permission assigned. These permissions are only available to accounts with Forms enabled. To enable this feature, contact your Account Manager or Business Development representative.                                                                         |
| \{OFFICE_ID}                        | An identifier for the office location that is responsible for the room itself. Retrieve this value with the [Offices:GetOffices](/docs/rooms-api/reference/offices/offices/getoffices) 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 calls 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.

> **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 formGroupsApi = new FormGroupsApi(apiClient);
```

**`Java`**

```java title="Java"
this.formGroupsApi = createFormGroupsApi(
        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(args["access_token"])
```

**`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. Retrieve an office ID

Next, make a GET request to your Rooms account by using the [Offices:GetOffices](/docs/rooms-api/reference/offices/offices/getoffices) method or supporting SDK method to get your office ID. Here’s how you make the call, but make sure to substitute your base path for \{BASE_PATH} and your API account ID for \{API_ACCOUNT_ID}. Select one of the returned office IDs to use in the next step.

**`Bash`**

```bash title="Bash"
printf \
    '
{
  "name": "Sample Room Form Group",
}' >$request_data
```

**`C#`**

```csharp title="C#"
var formGroupForCreate = new FormGroupForCreate(groupName);
```

**`Java`**

```java title="Java"
FormGroupForCreate formGroupForCreate = new FormGroupForCreate()
        .name(formGroupName);
```

**`Node.js`**

```javascript title="Node.js"
const form = new docusignRooms.FormGroupForCreate.constructFromObject({
  name: args.formGroupName,
});
```

**`PHP`**

```php title="PHP"
$form_group = new FormGroupForCreate(['name' => $args['form_group_name']]);
```

**`PowerShell`**

```text title="PowerShell"
# Construct the request body
$body = @"
  {
    "name": "Sample Room Form Group"
  }
"@
```

**`Python`**

```python title="Python"
form = FormGroupForCreate(name=args["form_group_name"])
```

**`Ruby`**

```ruby title="Ruby"
DocuSign_Rooms::RoomForCreate.new(
  {
    name: args[:group_name]
  }
)
```

## Step 4. Select a form group ID

To find the form group that you want to assign the office to, you need to make a GET request to obtain an available [form group ID](/docs/rooms-api/reference/forms/formgroups/getformgroups). The Rooms API will return a list of available form group IDs; select the one you want to continue through the example. Here’s how you make the call but make sure to substitute your API account ID for \{API_ACCOUNT_ID}.

**`Bash`**

```bash title="Bash"
Status=$(curl -w '%{http_code}' --request POST ${base_path}/restapi/v2/accounts/${API_ACCOUNT_ID}/form_groups \
    "${Headers[@]}" \
    --data-binary @${request_data} \
    --output ${response})
```

**`C#`**

```csharp title="C#"
var response = formGroupsApi.CreateFormGroupWithHttpInfo(accountId, formGroupForCreate);

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"
ApiResponse<FormGroup> response = formGroupsApi.createFormGroupWithHttpInfo(accountId, formGroupForCreate);

Map<String, List<String>> headers = response.getHeaders();
List<String> remaining = headers.get("X-RateLimit-Remaining");
List<String> reset = headers.get("X-RateLimit-Reset");

if (remaining != null & reset != null) {
    Instant resetInstant = Instant.ofEpochSecond(Long.parseLong(reset.get(0)));
    System.out.println("API calls remaining: " + remaining);
    System.out.println("Next Reset: " + resetInstant);
}

return response.getData();
```

**`Node.js`**

```javascript title="Node.js"
const formsGroupsApi = new docusignRooms.FormGroupsApi(dsApiClient);
const results = await new Promise((resolve, reject) => {
    formsGroupsApi.createFormGroup(args.accountId, {
      body: form,
    },
      (err, data, response) => {
      if (err) return reject(err);
      resolve({ data, response });
    });
  });

  let headers = results.response.headers;
  let remaining = headers['x-ratelimit-remaining'];
  let 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"
return $clientService->createFormGroup($args["account_id"], $form_group);
```

**`PowerShell`**

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

try {
    Write-Output "Response:"
    $response = Invoke-WebRequest -uri $uri -headers $headers -method POST -body $body
    $response.Content
    $obj = $response.Content | ConvertFrom-Json
    $formGroupID = $obj.formGroupId

    # Store formGroupID into the file .\config\FORM_GROUP_ID
    $formGroupID > .\config\FORM_GROUP_ID
}
catch {
    Write-Output "Unable to create a form group"
    # 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"
form_groups_api = FormGroupsApi(api_client)
(response, status, headers) = form_groups_api.create_form_group_with_http_info(
    body=form, 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::FormGroupsApi.new(api_client)
results, _status, headers = rooms_api.create_form_group_with_http_info(args[:account_id], body(args))

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

## Step 5. Call the Rooms API

Now that you have constructed your API headers, make a POST request to the [FormGroups:GrantOfficeAccessToFormGroup](/docs/rooms-api/reference/forms/formgroups/grantofficeaccesstoformgroup) method to grant office access to your form group for your Rooms account. Here’s how you make the call, but make sure to substitute your base path for \{BASE_PATH}, API account ID for \{API_ACCOUNT_ID}, form group ID for \{FORM_GROUP_ID}, and office ID for \{OFFICE_ID}.

**Note:** This Rooms API call does not require a request body, but still needs to be sent as a POST request.

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

**`Bash`**

```bash title="Bash"
Status=$(
    curl -w '%{http_code}' --request POST ${base_path}/restapi/v2/accounts/${API_ACCOUNT_ID}/form_groups/$FORM_GROUP_ID/grant_office_access/${OFFICE_ID} \
    "${Headers[@]}" \
    --data-binary @${request_data} \
    --output ${response}
)
```

**`C#`**

```csharp title="C#"
var response = formGroupsApi.GrantOfficeAccessToFormGroupWithHttpInfo(accountId, new Guid(formGroupId), officeId);

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);
}
```

**`Java`**

```java title="Java"
GrantOfficeAccessToFormGroupService.grantOfficeAccessToFormGroup(
        this.formGroupsApi,
        this.session.getAccountId(),
        args.getFormGroupId(),
        args.getOfficeId());
```

**`Node.js`**

```javascript title="Node.js"
const formsGroupsApi = new docusignRooms.FormGroupsApi(dsApiClient);
    const results = await new Promise((resolve, reject) => {
      formsGroupsApi.grantOfficeAccessToFormGroup(args.accountId, args.formGroupId, args.officeId,
      (err, data, response) => {
      if (err) return reject(err);
      resolve({ data, response });
    });
  });

  let headers = results.response.headers;
  let remaining = headers['x-ratelimit-remaining'];
  let 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_api = $clientService->getFromGroupsApi();
$response = $form_api->grantOfficeAccessToFormGroupWithHttpInfo(
    $args['form_group_id'],
    $args['office_id'],
    $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));
}
```

**`PowerShell`**

```text title="PowerShell"
$uri = "$base_path/restapi/v2/accounts/$APIAccountId/form_groups/$formGroupID/grant_office_access/$officeID"

try {
  Write-Output "Response:"
  $response = Invoke-WebRequest -uri $uri -headers $headers -method POST -body $body
  $response.StatusCode
  if ($response.StatusCode -eq "204") {
    Write-Output "Form group has been assigned to office ID."
  }

  # check that we have got a 204 Status code response
  if ($response.StatusCode -ne "204" ) {
    Write-Output "Unable to assign the provided form group ID to the provided office ID!"
    exit 1
  }
}
catch {
  Write-Output "Unable to grant office access to a form group"
  # 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"
form_groups_api = FormGroupsApi(api_client)

(response, status, headers) = form_groups_api.grant_office_access_to_form_group_with_http_info(
    form_group_id=args["form_group_id"], office_id=args["office_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"
form_groups_api = DocuSign_Rooms::FormGroupsApi.new(api_client)
begin
  response, _status, headers = form_groups_api.grant_office_access_to_form_group_with_http_info(args[:form_group_id], args[:office_id], args[:account_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
rescue Exception
  return { exception: 'Failed to grant office access to a form group' }
end
```

## Expected response

You will receive a 204 Status code response with an empty response body.

## 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).
* Learn more [Rooms API concepts](/docs/rooms-api/rooms101/concepts).
* See [How to create a form group](/docs/rooms-api/how-to/create-form-group).
* See [How to create a room with data](/docs/rooms-api/how-to/create-room-with-data).
* See [How to add forms to a room](/docs/rooms-api/how-to/add-form-to-room).
* 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.