Note: You can download a postman example of the below queries in this article's attachments.
Unicity Check
When creating or updating products, the Product Code is usually used as the unique identifier. Because of this, it is good practice to check for existence before creating a new product.
To do so, you can run the following query :
{
products(last: 10, filter: {code: "enter product code here"}) {
edges {
node {
code
description
dbId
}
}
}
}
If the answer is as follows, it means the project doesn't exist and you can proceed to create it :
{
"data": {
"products": {
"edges": null
}
}
}
If the answer is as follows, it means the project exists and you can proceed to update it :
{
"data": {
"products": {
"edges": [
{
"node": {
"code": "code",
"dbId": 12345678,
"description": "description"
}
}
]
}
}
}
Note: If the existence query returns more than one result, it means multiple entries of the queried resource share the same code. This might cause issues when unicity is needed in mutations, for example when creating an invoice against a customer. It would be a good idea to sanitize the data should that happen.
Product creation
Here is an example of product creation, mandatory fields are code and description only, use the rest according to your needs.
mutation {
addProducts(inputs: [{node: {
code: "123412341234"
description: "test"
#productGroup:{code:""}
#glObject1:{code:""}
#glObject2:{code:""}
#glObject3:{code:""}
#glObject4:{code:""}
#glObject5:{code:""}
}}]) {
edges {
node {
dbId
}
}
}
}
Note : Product groups are sometimes used to link products to account nominals, use this field if the entity has this setup.
Product update
Here is an example of a product update, dbId is returned by the existence check, use this to specify which product to update.
mutation {
updateProducts(inputs: [{node: {
dbId:28630394
code: "123412341234"
description: "test"
#productGroup:{code:""}
#glObject1:{code:""}
#glObject2:{code:""}
#glObject3:{code:""}
#glObject4:{code:""}
#glObject5:{code:""}
}}]) {
edges {
node {
dbId
}
}
}
}