Create a contract with a contract value

This tutorial shows you how to create a new contract with a contract value 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 using 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.
value The contract value.
Value
amount The contact value (amount).

Step 2. Enable a user role to set the contract value in contracts

To create contracts with contract value via the REST API, make sure the user's role has the corresponding user permission enabled in the Oneflow application.

  1. Find out your current user role under the Admin > Users tab.

  1. Go to the Roles tab, click your user role.

  1. Click the Permissions tab and check if the Can set value on others contracts option is enabled.

Step 3. 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": WORKSPACE_ID,"template_id": TEMPLATE_ID, "value":{"amount":"500.10"}}'
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, 
  "value":{
    "amount":"500.10"
  }
}

response = requests.post('https://api.oneflow.com/v1/contracts/create', 
                         headers=headers, json=data)

print(response.json())

This request outputs details about the contract you just created in JSON format; check the contract value to verify the amount.

Expected response

The output will include the contract value and the currency set in the Oneflow application as follows:

{
...
  "_private": {
    "name": "",
    "value": {
      "amount": "500.10",
      "currency": "SEK"
    }

...
}

Please see the Value section in the Data model category for more information about the output.

Response codes

StatusMeaningDescription
200OKReturns the created contract.
400Bad RequestInvalid format or content of the request.
404Not FoundA required entity is missing.
409ConflictA conflict occurred with the current state of the target resource.