Note: You can download a postman example of the below queries in this article's attachments.
Unicity Check
When creating or updating suppliers, the Supplier Code is usually used as the unique identifier. Because of this, it is good practice to check for existence before creating a new supplier.
To do so, you can run the following query :
{
suppliers(last: 10, filter: {code: "enter supplier code here"}) {
edges {
node {
code
description
dbId
}
}
}
}
If the answer is as follows, it means the supplier doesn't exist and you can proceed to create it :
{
"data": {
"suppliers": {
"edges": null
}
}
}
If the answer is as follows, it means the supplier exists and you can proceed to update it :
{
"data": {
"suppliers": {
"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.
Supplier creation
Here is an example of a supplier creation, mandatory fields are code and description only, use the rest according to your needs.
mutation{
addSuppliers(inputs: [{node: {
code: "TESTCODE2"
description: "Test descrition"
payMethod: {description: "Manual Payment"}
bank: {code: "BNP"}
bankAccount: "12345678"
email: "test@email.com"
phone: "07123123123"
streetAddress: "4th Floor, Tower Wharf, Cheese Ln"
zipCode: "BS2 0JJ"
place: "Bristol"
country: {code: "GB"}
streetAddress2: "4th Floor, Tower Wharf, Cheese Ln"
zipCode2: "BS2 0JJ"
place2: "Bristol"
country2: {code: "GB"}
}}]) {
edges {
node {
dbId
}
}
}
}
Note: If countries are passed, ISO Alpha-2 country codes need to be used.
Supplier update
Here is an example of a supplier update, dbId is returned by the existence check, use this to specify which supplier to update.
mutation{
updateSuppliers(inputs: [{node: {
dbId: "26468971"
code: "TESTCODE"
description: "Test descrition"
payMethod: {description: "Manual Payment"}
bank: {code: "BNP"}
bankAccount: "12345678"
email: "test@email.com"
phone: "07123123123"
streetAddress: "4th Floor, Tower Wharf, Cheese Ln"
zipCode: "BS2 0JJ"
place: "Bristol"
country: {code: "GB"}
streetAddress2: "4th Floor, Tower Wharf, Cheese Ln"
zipCode2: "BS2 0JJ"
place2: "Bristol"
country2: {code: "GB"}
}}]) {
edges {
node {
dbId
}
}
}
}