Skip to navigation

How to get a room with filters

View as Markdown

This topic demonstrates how to return rooms filtered by your parameters using the Rooms API. The sample code for this topic filters for all rooms that have had their field data updated within the last 10 days, as shown on the Details tab in the UI.

Run this code example from our Quickstart or launcher projects: Bash, C#, Java, Node.js, PHP, PowerShell, Python, or Ruby.

Required data

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

Data elementDescription
{API_ACCOUNT_ID}A GUID 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 page.
Rooms enabled for your accountYou will need access enabled to use the Rooms API. See creating a Rooms developer 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.

See Authentication 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

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

declare -a Headers=('--header' "Authorization: Bearer ${ACCESS_TOKEN}"
'--header' "Accept: application/json"
'--header' "Content-Type: application/json")

Step 3. Prepare your request parameters

Next, prepare your request by populating your query parameters. For this how-to, you will use two dates to filter for all rooms with updated field data after a given date that is set dynamically to 10 days in the past.

Date filtering format can be set using either mm-dd-yyyy hh:mm:ss format or mm-dd-yyyy format. When filtering by mm-dd-yyyy, the midnight time of 0:00:00 is used. This example has the end date set forward one day to account for updates occurring on today’s date.

if date -v -10d &>/dev/null; then
# Mac
# past=`date -v -10d '+%Y-%m-%dT%H:%M:%S%z'`
past=$(date -v -10d '+%Y-%m-%d')
# Set the date 1 day forward to account for changes made today
# current=`date -v +1d '+%Y-%m-%dT%H:%M:%S%z'`
current=$(date -v +1d '+%Y-%m-%d')
else
# Not a Mac
# past=`date --date='-10 days' '+%Y-%m-%dT%H:%M:%S%z'`
past=$(date --date='-10 days' '+%Y-%m-%d')
# Set the date 1 day forward to account for changes made today
# current=`date --date='+1 days' '+%Y-%m-%dT%H:%M:%S%z'`
current=$(date --date='+1 days' '+%Y-%m-%d')
fi

Step 4. Call the Rooms API

Now that you have constructed your API headers and request body, you can, make a GET request to the Rooms API to return a filtered set of rooms. Here’s how you make the call, but make sure to substitute your API account ID for {ACCOUNT_ID}.

View the source code for this how-to on GitHub: Bash, C#, Java, Node.js, PHP, PowerShell, Python, or Ruby.

response=$(mktemp /tmp/response-cw.XXXXXX)
curl -w '%{http_code}' -i --request GET "https://demo.rooms.docusign.com/restapi/v2/accounts/${account_id}/rooms?fieldDataChangedStartDate=${past}&fieldDataChangedEndDate=${current}" \
"${Headers[@]}" \
--output ${response}

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
{
"rooms":
[
{
"roomId": 3xxxx5,
"name": "Sample Rooms Creation",
"officeId": 3xxx2,
"createdDate": "2020-08-06T15:38:38",
"createdByUserId": 0,
"closedStatusId": "",
"fieldDataLastUpdatedDate": "2020-08-06T20:38:38.56"
},
{
"roomId": 3xxxx4,
"name": "Sample Rooms Creation from Template",
"officeId": 3xxx2,
"createdDate": "2020-08-06T15:33:29",
"createdByUserId": 0,
"closedStatusId": "",
"fieldDataLastUpdatedDate": "2020-08-06T20:33:30.107"
},
{
"roomId": 3xxxx6,
"name": "Sample Rooms Creation",
"officeId": 3xxx2,
"createdDate": "2020-08-06T13:54:15",
"createdByUserId": 0,
"closedStatusId": "",
"fieldDataLastUpdatedDate": "2020-08-06T19:10:32.92"
}
],
"resultSetSize": 3,
"startPosition": 0,
"endPosition": 2
}

Next steps