Before you begin
This guide is intended for users who have been approved to access the FastDraft API. You will need an API-enabled FastDraft account, the correct API URI for your instance, and permission to install or use an API client.
Overview
This article explains how to create a Bruno collection, authenticate with FastDraft, obtain the required security tokens, and run two test requests. It also shows how to store the tokens as environment variables so they are applied automatically to future requests.
Use a dedicated API user
We strongly recommend using a separate FastDraft account for API access rather than an account that is also used to sign in through the FastDraft interface.
- Using the same account for the API and the user interface can cause one session to invalidate the other, creating repeated reauthentication.
- Separate accounts make API activity easier to identify in server and API logs when troubleshooting is required.
- Dedicated accounts support the security principle of assigning only the permissions required for a particular purpose.
- Where SSO is enabled, API access requires an account that can bypass SSO. This should not normally be enabled on an everyday user account.
Choose an API client
Built Intelligence uses Bruno for development and direct API access. Bruno stores collections as text-based files, which can be managed in a repository and compared using Git or another text comparison tool.
You can use another API request and response manager, cURL, or a command-line tool if preferred. The examples in this article use Bruno.
API reference documentation
The FastDraft API is documented using Swagger. Each endpoint lists the request method, expected parameters, and response type.
Open the FastDraft API documentation
Important
Do not use endpoints shown as crossed out in the documentation. These endpoints are obsolete and may be removed without notice.
API usage guidance
- Reading individual records or lists is supported.
- If a RegisterList endpoint is available, use it instead of the equivalent List endpoint because it is more performant.
- Do not create, save, edit, or update data through the API without first discussing the requirement with your account manager and the FastDraft development team.
Warning
Writing to the API can affect contract data. Remedial work following an incorrect API write may not be possible and, where it is possible, is a chargeable service.
1. Create a Bruno collection and environment
- Install and open Bruno.
- Select Create Collection and enter a suitable collection name.
- Open Environments and create a new environment for the FastDraft instance.
Create a collection from the Bruno workspace.
Open the collection and select Environments.
Add an environment variable named server. Set its value to the API base URL for your FastDraft instance.
Create the server environment variable.
Finding the API URL
The API address is based on the normal address for your FastDraft instance. Insert api immediately before the first full stop. For example, https://app-uk.builtintelligence.com/ becomes https://app-ukapi.builtintelligence.com/. Contact your account manager if you are unsure which URI to use.
Using {{server}} in each request avoids hard-coding the same base address repeatedly.
2. Request a bearer token
FastDraft uses a bearer token to authenticate API requests. You normally request this token at the start of a sequence of calls and request another when it expires.
- Select Add Request and choose HTTP.
- Set the request method to POST.
- Enter the endpoint shown below.
- On the Body tab, select Form URL Encoded and add grant_type, username, and password.
Add a new HTTP request.
POST {{server}}/token
grant_type: password
username: your API user email address
password: your API user password
Add the token request parameters as form URL encoded values.
A successful response includes an access_token. Copy the value of access_token for the next request. Other fields may vary depending on the permissions assigned to the account.
{
"access_token": "VeryLongString",
"token_type": "bearer",
"expires_in": 31535999,
"userName": "apiuser@example.com"
}
If you receive a 401 response
Confirm that the request is a POST to {{server}}/token and check the API username and password. Subsequent calls will also return 401 Authorization has been denied if a valid bearer token is not supplied.
3. Request the CSRF token
FastDraft also requires a CSRF token to protect requests against cross-site request forgery.
- Open the collection menu and select New Request.
- Create an HTTP request named CSRF.
- Set the method to GET and enter the endpoint below.
- Open the Auth tab, select Bearer Token, and paste the access_token from the previous step.
Create another request from the collection menu.
Configure the CSRF request.
GET {{server}}/api/generic
Add the bearer token on the Auth tab.
The response contains a value with a prefix followed by a dash. Copy only the text after the dash. This is the CSRF token you will use in later requests.
Example response: VALID-AAAAAAaaaaaBBBBBbbbbbCCCCCccccc
CSRF token to copy: AAAAAAaaaaaBBBBBbbbbbCCCCCccccc
If you receive an invalid headers response
A 400 response containing invalid_token and Invalid Headers usually means that the CSRF token is missing or incorrect.
4. Run a basic authentication test
Use the system links request to confirm that the bearer token and CSRF token are being accepted. This endpoint does not require company-level or contract-level permissions, so it is useful for isolating authentication issues.
- Create an HTTP request named Test Links.
- Set the method to GET and enter the endpoint below.
- On the Auth tab, select Bearer Token and paste the access token.
- On the Headers tab, add a header named csrf-token and paste the CSRF token as its value.
- Send the request.
Create the Test Links request.
GET {{server}}/api/SystemLinks/GetList
Add the CSRF token to the request headers.
Troubleshooting
A missing or invalid bearer token normally returns 401. A missing or invalid CSRF header normally returns a 400 invalid headers response.
A successful response returns the configured system help links, for example:
{
"LinkID": 4,
"LastEditedBy": "System",
"Name": "Contact User Support",
"URL": "mailto:contractmanagement@yourdomain.co.uk",
"Target": "_blank",
"Order": 1
}
5. Test contract access
Once the authentication test succeeds, use the contract register endpoint to check which contracts the API user can access.
- Create an HTTP request named List Contracts.
- Set the method to GET and enter the endpoint below.
- Add the bearer token and CSRF token in the same way as the Test Links request.
- Send the request.
Create the List Contracts request.
GET {{server}}/api/Contract/RegisterList
The response contains the contracts and aggregated metadata available to the API user. The user will only see contracts for which they have Contract User access or suitable elevated permissions.
An empty response can be valid
If the list is empty, the account does not currently have permission to view any contracts.
6. Automate token handling
To avoid copying the bearer token and CSRF token into every request, store both values in environment variables and configure the collection to apply them automatically.
Create the token variables
- Open the collection, select Environments, and choose your environment.
- Add variables named token and csrf. Leave their values blank, then save the environment.
Open the collection environment.
Add the token and csrf environment variables.
Save the bearer token automatically
- Open the Token request.
- Open the Script tab and select Post Response.
- Paste the script below and save the request.
Add a Post Response script to the Token request.
let respoBody = res.getBody();
let accessTokShort = respoBody.access_token;
bru.setEnvVar("token", accessTokShort);
This script reads the token response and stores access_token in the {{token}} environment variable.
Save the CSRF token automatically
- Open the CSRF request.
- Open the Script tab and select Post Response.
- Paste the script below and save the request.
Add a Post Response script to the CSRF request.
let respoBody = res.getBody();
let csrfTok = respoBody.replace('ADMIN-', '').replace('VALID-', '');
bru.setEnvVar("csrf", csrfTok);
This script removes the expected prefix and stores the remaining value in the {{csrf}} environment variable.
Apply authentication at collection level
- Select the collection name and open the Auth tab.
- Set the authentication type to Bearer Token.
- Enter {{token}} as the token value and save the collection.
Configure bearer authentication at collection level.
- Open the collection Script tab and select Pre Request.
- Paste the script below and save the collection.
Add the CSRF header in the collection Pre Request script.
req.setHeader('csrf-token', '{{csrf}}')
The collection will now add the CSRF header to each request automatically.
Update the existing requests
Open the CSRF, Test Links, and List Contracts requests one at a time, then complete the following changes:
- On the Auth tab, change the request from a manually entered bearer token to Inherit.
- Delete the manually entered csrf-token header.
Set each request to inherit authentication from the collection. Set each request to inherit authentication from the collection.
Remove the manually entered CSRF header.
For future requests, set authentication to Inherit. The request will use the collection bearer token and the collection Pre Request script will add the CSRF header.
The completed collection with the authentication and test requests.
Recommended request sequence
| Order | Request | Purpose |
| 1 | POST {{server}}/token | Obtain and store the bearer token. |
| 2 | GET {{server}}/api/generic | Obtain and store the CSRF token. |
| 3 | Your API request | Run the required read operation using inherited authentication. |
Common errors
| Response | Likely cause | What to check |
| 401 Authorization has been denied | Bearer token is missing, invalid, or expired. | Check the Auth tab, rerun the Token request, and confirm the request inherits collection authentication. |
| 400 invalid_token / Invalid Headers | CSRF token is missing or invalid. | Rerun the CSRF request and confirm the collection Pre Request script is adding csrf-token. |
| Empty contract list | The account has no accessible contracts. | Review Contract User access or elevated permissions in FastDraft. |
| Unexpected sign-outs or repeated authentication | The same account is being used for API and UI access. | Use a dedicated API account. |
Comments
0 comments
Please sign in to leave a comment.