Product group
In this tutorial, you'll learn how to perform various operations related to product groups in a contract.
Update product groups
There are two ways of updating an existing product group in a contract:
- Using the PUT /contracts/{contract_id}/product_groups/{product_group_id} endpoint, you can update products within a product group and its configuration.
- Using the PUT /contracts/{contract_id}/product_groups endpoint, you can update the products within a product group and its configuration.
Note:
Using the endpoints provided, you can manage the product group configuration and individual products. Within a product group, you will be able to:
- Create a new product
- Delete an existing product
- Update product details
- Rearrange the order of products
Step 1. Obtain the necessary information
To run the script described in this step, 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. |
Path parameters | |
CONTRACT_ID |
The unique ID of the contract where you want to update a product. You can find the contract ID using the contracts endpoint. |
PRODUCT_GROUP_ID |
The unique ID of the product group where you want to update the configuration and products. |
Body | configuration[object] |
price_affixes[object]
|
Postfix and prefix of a contract product price. |
prefix
|
The product price prefix. |
postfix
|
The product price postfix. |
hide_price_summation
|
If true, the price summation will be hidden. |
columns[list]
|
|
enabled
|
If true, the column is enabled and visible. |
key
|
One of the product group column keys. ex: description
|
label
|
The product group column label related to the key above.
|
counterpart_edit
|
If true, the counterpart can edit products in the contract. |
name
|
|
enabled
|
If true, the product group's name is enabled and visible |
label
|
Profuct group name |
price_precision
|
Define number of decimal places for price values |
quantity_precision
|
Define number of decimal places for quantity type quantities | products[list] |
counterparty_lock
|
Indicates if the counterparty can edit the product in the contract. The default value is false .
|
description
|
The description of the product. |
name
|
The name of the product. |
_private_ownerside | |
custom_id
|
A custom identifier you can use to address the products in a contract. |
price_1 | The price of the product. |
price_2 | The alternative price of the product, for example, the monthly payment fee. |
discount_percent
|
The percentage discount off the base price. |
base_amount | |
amount
|
The sum of the base price of the product, excluding the discount. |
discount_amount | |
amount
|
The amount of the discount from the base price. This value must not be greater than the base price. |
quantity | |
amount
|
The number of selected products. |
type
|
One of the product quantity types (multiple_choice, single_choice, quantity ).
|
Step 2. Run the code
Depending on the selected endpoint, replace the values of the parameters in the following commands with the actual data from your account and run it:
Update a product group by ID
curl --request PUT \
--url https://api.oneflow.com/v1/contracts/10015/product_groups/75861 \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-oneflow-api-token: 9841f1ee533681c3ea6a438560f2bb6c73b76675' \
--header 'x-oneflow-user-email: [email protected]' \
--data '
{
"configuration": {
"price_affixes": {
"prefix": "Rs"
},
"hide_price_summation": false,
"columns": [
{
"enabled": true,
"key": "name",
"label": "Flowers"
},
{
"enabled": true,
"key": "count",
"label": "Value"
}
],
"counterpart_edit": false
},
"products": [
{
"counterparty_lock": false,
"price_1": {
"base_amount": {
"amount": "100.00"
},
"discount_amount": {
"amount": "0.00"
},
"discount_percent": {
"amount": "10.000"
}
},
"quantity": {
"type": "multiple_choice",
"amount": "1"
},
"description": "fresh rose",
"name": "Rose"
},
]
}
'
import requests
url = "https://api.oneflow.com/v1/contracts/10015/product_groups/75861"
payload = {
"configuration": {
"price_affixes": {"prefix": "Rs"},
"hide_price_summation": False,
"columns": [
{
"enabled": True,
"key": "name",
"label": "Flowers"
},
{
"enabled": True,
"key": "count",
"label": "ValueX"
}
],
"counterpart_edit": False
},
"products": [
{
"counterparty_lock": False,
"price_1": {
"base_amount": {"amount": "100.00"},
"discount_amount": {"amount": "0.00"},
"discount_percent": {"amount": "10.000"}
},
"quantity": {
"type": "multiple_choice",
"amount": "1"
},
"description": "fresh rose",
"name": "shoes"
},
]
}
headers = {
"accept": "application/json",
"x-oneflow-api-token": "9841f1ee533681c3ea6a438560f2bb6c73b76675",
"x-oneflow-user-email": "[email protected]",
"content-type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)
Expected response
{
"_private_ownerside": {
"created_time": "2021-01-29T08:55:46+00:00",
"updated_time": "2021-01-29T08:55:46+00:00"
},
"enabled_columns": [
{
"enabled": true,
"key": "name"
},
{
"enabled": true,
"key": "description"
},
{
"enabled": true,
"key": "price_1"
},
{
"enabled": true,
"key": "price_2"
},
{
"enabled": true,
"key": "count"
}
],
"configuration": {
"columns": [
{
"enabled": true,
"key": "name",
"label": "Flowers"
},
{
"enabled": true,
"key": "description",
"label": "Description"
},
{
"enabled": true,
"key": "price_1",
"label": "Price 1"
},
{
"enabled": true,
"key": "price_2",
"label": "Price 2"
},
{
"enabled": true,
"key": "count",
"label": "Value"
}
],
"counterpart_edit": false,
"hide_price_summation": false,
"name": {
"enabled": false,
"label": "Untitled"
},
"price_affixes": {
"prefix": "Rs",
"postfix": ""
},
"price_precision": 2,
"quantity_precision": 0
},
"id": 75861,
"products": [
{
"_private_ownerside": {
"created_time": "2021-01-29T08:55:46+00:00",
"custom_id": "custom_id_set_by_user",
"updated_time": "2021-01-29T08:55:46+00:00"
},
"counterparty_lock": false,
"description": "fresh rose",
"id": 135805,
"name": "Rose",
"price_1": {
"base_amount": {
"amount": "100.00"
},
"discount_amount": {
"amount": "0.00"
},
"discount_percent": "10.000"
},
"price_2": {
"amount": {
"amount": "0.000"
},
"base_amount": {
"amount": "0.000"
},
"discount_amount": {
"amount": "0.000"
},
"discount_percent": "0.000"
},
"quantity": {
"amount": 1,
"type": "multiple_choice"
}
}
]
}
Update a list of product groups
curl --request PUT \
--url https://api.oneflow.com/v1/contracts/10015/product_groups \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'x-oneflow-api-token: 9841f1ee533681c3ea6a438560f2bb6c73b76675' \
--header 'x-oneflow-user-email: [email protected]' \
--data '
{
"product_groups": [
{
"configuration": {
"price_affixes": {
"prefix": "Rs"
},
"hide_price_summation": false,
"columns": [
{
"enabled": true,
"key": "name",
"label": "Flowers"
},
{
"enabled": true,
"key": "count",
"label": "Value"
}
],
"counterpart_edit": false
},
"products": [
{
"counterparty_lock": false,
"price_1": {
"base_amount": {
"amount": "100.00"
},
"discount_amount": {
"amount": "0.00"
},
"discount_percent": "10.000"
},
"quantity": {
"type": "multiple_choice",
"amount": "1"
},
"description": "fresh rose",
"name": "Rose"
},
],
"id": 75861
}
]
}
'
import requests
url = "https://api.oneflow.com/v1/contracts/10015/product_groups"
payload = {"product_groups": [
{
"configuration": {
"price_affixes": {"prefix": "Rs"},
"hide_price_summation": False,
"columns": [
{
"enabled": True,
"key": "name",
"label": "Flowers"
},
{
"enabled": True,
"key": "count",
"label": "ValueX"
}
],
"counterpart_edit": False
},
"products": [
{
"counterparty_lock": False,
"price_1": {
"base_amount": {"amount": "100.00"},
"discount_amount": {"amount": "0.00"},
"discount_percent": "10.000"
},
"quantity": {
"type": "multiple_choice",
"amount": "1"
},
"description": "fresh rose",
"name": "shoes"
},
],
"id": 75861
}
]}
headers = {
"accept": "application/json",
"x-oneflow-api-token": "9841f1ee533681c3ea6a438560f2bb6c73b76675",
"x-oneflow-user-email": "[email protected]",
"content-type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)
Expected response
{
"count": 1,
"data": [
{
"_private_ownerside": {
"created_time": "2021-01-29T08:55:46+00:00",
"updated_time": "2021-01-29T08:55:46+00:00"
},
"enabled_columns": [
{
"enabled": true,
"key": "name"
},
{
"enabled": true,
"key": "description"
},
{
"enabled": true,
"key": "price_1"
},
{
"enabled": true,
"key": "price_2"
},
{
"enabled": true,
"key": "count"
}
],
"configuration": {
"columns": [
{
"enabled": true,
"key": "name",
"label": "Flowers"
},
{
"enabled": true,
"key": "description",
"label": "Description"
},
{
"enabled": true,
"key": "price_1",
"label": "Price 1"
},
{
"enabled": true,
"key": "price_2",
"label": "Price 2"
},
{
"enabled": true,
"key": "count",
"label": "Value"
}
],
"counterpart_edit": false,
"hide_price_summation": false,
"name": {
"enabled": false,
"label": "Untitled"
},
"price_affixes": {
"prefix": "Rs",
"postfix": ""
},
"price_precision": 2,
"quantity_precision": 0
},
"id": 75861,
"products": [
{
"_private_ownerside": {
"created_time": "2021-01-29T08:55:46+00:00",
"custom_id": "custom_id_set_by_user",
"updated_time": "2021-01-29T08:55:46+00:00"
},
"counterparty_lock": false,
"description": "fresh rose",
"id": 135805,
"name": "Rose",
"price_1": {
"base_amount": {
"amount": "100.00"
},
"discount_amount": {
"amount": "0.00"
},
"discount_percent": "10.000"
},
"price_2": {
"amount": {
"amount": "0.000"
},
"base_amount": {
"amount": "0.000"
},
"discount_amount": {
"amount": "0.000"
},
"discount_percent": "0.000"
},
"quantity": {
"amount": 1,
"type": "multiple_choice"
}
}
]
}
]
}
Get a product group by ID
Using the GET /contracts/{contract_id}/product_groups/{product_group_id} endpoint, you can get the products and configuration of a product group in a contract.
Step 1. Obtain necessary information
To run the script described in this step, 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. |
Path parameters | |
CONTRACT_ID |
The unique ID of the contract where you want to update a product. You can find the contract ID using the contracts endpoint. |
PRODUCT_GROUP_ID |
The unique ID of the product group which you want to get the configuration and products. |
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 GET \
--url https://api.oneflow.com/v1/contracts/10015/product_groups/75861 \
--header 'accept: application/json' \
--header 'x-oneflow-api-token: 9841f1ee533681c3ea6a438560f2bb6c73b76675' \
--header 'x-oneflow-user-email: [email protected]'
import requests
url = "https://api.oneflow.com/v1/contracts/10015/product_groups/75861"
headers = {
"accept": "application/json",
"x-oneflow-api-token": "9841f1ee533681c3ea6a438560f2bb6c73b76675",
"x-oneflow-user-email": "[email protected]"
}
response = requests.get(url, headers=headers)
print(response.text)
Expected response
{
"_private_ownerside": {
"created_time": "2021-01-29T08:55:46+00:00",
"updated_time": "2021-01-29T08:55:46+00:00"
},
"enabled_columns": [
{
"enabled": true,
"key": "name"
},
{
"enabled": true,
"key": "description"
},
{
"enabled": true,
"key": "price_1"
},
{
"enabled": true,
"key": "price_2"
},
{
"enabled": true,
"key": "count"
}
],
"configuration": {
"columns": [
{
"enabled": true,
"key": "name",
"label": "Flowers"
},
{
"enabled": true,
"key": "description",
"label": "Description"
},
{
"enabled": true,
"key": "price_1",
"label": "Price 1"
},
{
"enabled": true,
"key": "price_2",
"label": "Price 2"
},
{
"enabled": true,
"key": "count",
"label": "Value"
}
],
"counterpart_edit": false,
"hide_price_summation": false,
"name": {
"enabled": false,
"label": "Untitled"
},
"price_affixes": {
"prefix": "Rs",
"postfix": ""
},
"price_precision": 2,
"quantity_precision": 0
},
"id": 75861,
"products": [
{
"_private_ownerside": {
"created_time": "2021-01-29T08:55:46+00:00",
"custom_id": "custom_id_set_by_user",
"updated_time": "2021-01-29T08:55:46+00:00"
},
"counterparty_lock": false,
"description": "fresh rose",
"id": 135805,
"name": "Rose",
"price_1": {
"base_amount": {
"amount": "100.00"
},
"discount_amount": {
"amount": "0.00"
},
"discount_percent": "10.000"
},
"price_2": {
"amount": {
"amount": "0.000"
},
"base_amount": {
"amount": "0.000"
},
"discount_amount": {
"amount": "0.000"
},
"discount_percent": "0.000"
},
"quantity": {
"amount": 1,
"type": "multiple_choice"
}
}
]
}
Response codes
Status | Meaning | Description |
---|---|---|
200 | OK | Returns the relevant product group/updated product groups with products details. |
400 | Bad Request | Invalid format or content of the request. |
401 | Unauthorized | The API token or the user email is invalid. |
403 | Forbidden | The request is not authorized by the server. |
404 | Not Found | A required entity is missing. |
409 | Conflict | A conflict occurred with the current state of the target resource. |
Updated 2 days ago