Create a basic contract
This tutorial shows you how to create a new contract from an existing template using the REST API. You will also learn what data elements you’ll need for this and how to obtain them.
Step 1. Obtain necessary information
To run the script described in this tutorial, you’ll need the following data:
Headers | |
x-oneflow-api-token
|
You will only be able to run the script by providing a valid API token. You can create an API token in the Oneflow web application. Find out more in the Authentication section. |
x-oneflow-user-email
|
Your Oneflow user account email. You can find all user-related information using the users endpoint. |
Body | |
workspace_id
|
The unique ID of the workspace where you want to create your contract. You can find the workspace ID using the workspaces endpoint. |
template_id
|
The unique ID of the template you want to use for creating your contract. You can find the template ID using the templates endpoint. |
Step 2. Run the code
Replace the values of the parameters in the following command with the actual data from your account and run it:
curl --request POST \
--url https://api.oneflow.com/v1/contracts/create \
--header 'content-type: application/json' \
--header 'x-oneflow-api-token: API_TOKEN' \
--header 'x-oneflow-user-email: USER_EMAIL' \
--data '{"workspace_id": 130406,"template_id": 756510}'
import requests
headers = {
'content-type': 'application/json',
'x-oneflow-api-token': 'API_TOKEN',
'x-oneflow-user-email': 'USER_EMAIL',
}
data = {"workspace_id": WORKSPACE_ID,"template_id": TEMPLATE_ID}
response = requests.post('https://api.oneflow.com/v1/contracts/create',
headers=headers, json=data)
print(response.json())
When you create a contract using the template ID, Oneflow copies the template’s contents to the new contract. See the data model Contract for more information.
Expected response
This request will output details about the contract you created in JSON format.
Please see the Contract section in the Data model category for more information about the output.
Response codes
Status | Meaning | Description |
---|---|---|
200 | OK | Returns the created contract. |
400 | Bad Request | Invalid format or content of the request. |
404 | Not Found | A required entity is missing. |
409 | Conflict | A conflict occurred with the current state of the target resource. |
Troubleshooting
To verify an error, log into the Oneflow application using the email address of the Oneflow user attempting the request.
Then choose the corresponding workspace, and create a new contract from an active template within that workspace.
Error when supplying incorrect workspace ID with correct template ID:
{
"detail": "The template used to create a contract needs to be in the target workspace, and must be visible. Please share the template with the workspace you want to create the contract in, and make sure it is visible.",
"error_code": 4040003,
"parameter_problems": {
"template_id": [
"The workspace does not contain the template from which you are trying to create a contract."
]
},
"request_id": "_40gwRj7zSYzXI6ySvuwFc1u9Pjz26mr1_XCA0fNsAyrWKwaLhZ_qQ==",
"status": 404,
"title": "Not Found",
"type": "https://api.oneflow.com/v1/error_codes/4040003"
}
Error when supplying correct workspace ID with incorrect template ID:
{
"detail": "An object referenced in the request was not found. It might have been deleted or you might have lost access to it. Please check that the object still exists and you still have permission to access it.",
"error_code": 4040000,
"parameter_problems": {
"template_id": [
"This object does not exist or the user does not have access to it."
]
},
"request_id": "LR60DUtC4SthfIyFGHnxTVM8c-ljEyFpiVsUxP-jzw7qc5xcDU07bA==",
"status": 404,
"title": "Not Found",
"type": "https://api.oneflow.com/v1/error_codes/4040000"
}
Updated almost 2 years ago