Creating a Webhook (BuildingConnected)
This walkthrough demonstrates how to create a webhook that notifies your app when a BuildingConnected event occurs, such as a new bid revision or a comment on an opportunity, so your app can react without polling. The steps include selecting an event type, finding your company ID to use as the webhook scope, preparing the callback, creating and verifying the webhook, testing the webhook, and verifying callback authenticity.
For more details about the BuildingConnected API, see the BuildingConnected Field Guide.
Before You Begin
- A BuildingConnected account, with your BuildingConnected user linked to an Autodesk ID. See How to connect your Autodesk ID to BuildingConnected.
- A subscription to the relevant BuildingConnected product for the events you want: bid events require BuildingConnected Pro, and opportunity events require Bid Board Pro.
- Register an app and select both the BuildingConnected API and the Webhooks API.
- Acquire a three-legged access token with the
data:readanddata:createscopes. For choosing and acquiring an access token, see Authentication for Webhooks.
Step 1: Select an Event Type
BuildingConnected events belong to the autodesk.construction.bc system.
The Webhooks service supports these BuildingConnected events:
| Event | Trigger |
|---|---|
bid.created-1.0 |
When a new bid revision is created. |
opportunity.created-1.0 |
When a new opportunity is created. |
opportunity.status.updated-1.0 |
When an opportunity’s status is updated. |
opportunity.comment.created-1.0 |
When a new opportunity comment is created. |
opportunity.comment.updated-1.0 |
When an opportunity comment is updated. |
opportunity.comment.deleted-1.0 |
When an opportunity comment is deleted. |
You can cover several events with one webhook by using the asterisk (*) wildcard, which matches zero or more characters. For example, opportunity.comment.*-1.0 matches the three comment events above. See Supported Events.
In this walkthrough, assume that you want to subscribe to opportunity.comment.created-1.0.
Step 2: Find Your Company ID
The scope of a BuildingConnected webhook is your company ID. One webhook covers the chosen event for your whole company, not for a single project or opportunity.
Call GET users/me and read the company ID from results.companyId in the response.
Step 3: Prepare the Callback
The Webhooks service delivers each notification as an HTTP POST request to your callback URL. The URL must be reachable from the internet and must acknowledge the request quickly.
See Configuring Your Server for what your callback has to do and how to expose a local server while developing.
Step 4: Create the Webhook
Create the webhook before the activity you want to hear about takes place. A webhook receives only events that occur while it can deliver, so it does not receive events from before it existed.
Create the webhook by calling POST systems/:system/events/:event/hooks.
Set callbackUrl to the callback URL you prepared in Step 3, and set scope to {"companyId": "<your company ID>"} using the value you found in Step 2. companyId is the scope name for BuildingConnected events.
Optional fields such as hookAttribute and filter are described in the Webhooks Field Guide and Callback Filtering.
If your data is not in the default US region, specify the region on the request. See Regionalization and Data Residency.
If the request returns 401 or 403, confirm your BuildingConnected user is linked to an Autodesk ID and that you have the product subscription the event requires, in addition to the checks in Authentication for Webhooks.
If the request returns 400, confirm you are using companyId as the scope name, not a project ID, and that the event name is spelled exactly as listed in Step 1.
To create a webhook in the BuildingConnected alpha environment, use autodesk.construction.bc.alpha as the system value instead of autodesk.construction.bc.
Request
curl -X 'POST' \
-v 'https://developer.api.autodesk.com/webhooks/v1/systems/autodesk.construction.bc/events/opportunity.comment.created-1.0/hooks' \
-H 'Content-Type: application/json' \
-H 'authorization: Bearer <ACCESS_TOKEN>' \
-d '{
"callbackUrl": "https://myapp.example.com/callback",
"scope": {
"companyId": "594206015caedd954831e5b8"
}
}'
Response
A successful request returns 201 with an empty body and a Location header (or location if your connection uses HTTP/2):
HTTP/1.1 201
Location: https://developer.api.autodesk.com/webhooks/v1/systems/autodesk.construction.bc/events/opportunity.comment.created-1.0/hooks/0f60f6a0-996c-11e7-abf3-51d68cff984c
Content-Length: 0
Note the Location value (returned as location if your connection uses HTTP/2). Its final path segment is the hookId. You can use the hookId together with the system and event to retrieve, update, or delete the webhook.
If the request returns 401 or 403, check your access token, its type, and its scopes. Confirm your BuildingConnected user is linked to an Autodesk ID and that you have the product subscription the event requires. See Authentication for Webhooks.
If the request returns 400, confirm you are using companyId as the scope name, not a project ID, and that the event name is spelled exactly as listed in Step 1.
If the request returns 409, a webhook already exists for that callback URL, scope, and event. Retrieve your webhooks before creating another.
If the request returns 429, you have exceeded a rate limit. Wait, then retry. See Rate Limits and Quotas.
Step 5: Verify the Webhook
Confirm the webhook exists and is configured as you intended.
Request
curl -v 'https://developer.api.autodesk.com/webhooks/v1/hooks' \
-H 'authorization: Bearer <ACCESS_TOKEN>'
Response
In the entry for your new webhook, check that status is active, system is autodesk.construction.bc, event is the event you chose, scope holds your company ID, and callbackUrl is correct. See Retrieve a List of Webhooks.
If the webhook is not in the list, you may be listing against a different region than the one you created it in. See Regionalization and Data Residency.
For more information about webhook status and diagnosing delivery problems, see Monitoring and Troubleshooting.
Step 6: Test the Webhook
Trigger the event by performing the corresponding action in BuildingConnected. For opportunity.comment.created-1.0, add a comment to an opportunity belonging to the company whose ID you used as the scope.
Your callback URL then receives a POST request describing what happened. For the payload of the event you subscribed to, see its page under BuildingConnected Events.
If the action happened but no callback arrived, confirm the webhook existed and was active when the action occurred, that the activity belongs to the company in the scope, and that your callback is reachable. For more information about diagnosing callback delivery problems, see Monitoring and Troubleshooting.
If deliveries keep failing, the webhook becomes inactive. Fix the callback, then reactivate it. See Event Delivery Guarantees.
If the BuildingConnected activity itself did not behave as expected, see the BuildingConnected Field Guide.
Step 7: Verify Callback Authenticity
Your callback URL is reachable by anyone, so verify that a callback genuinely came from the Webhooks service before acting on it.
The access token and the secret token serve different purposes:
- The access token authorizes the calls your app makes to create and manage webhooks.
- The secret token you set is used to sign each callback, so your server can check it.
The access token is not sent with the callback.