This article covers a few general aspects of the syntax and use of Xledger's GraphQL API. You can also refer to the documentation.
Mass mutations
Most mutations in Xledger's API have a mass mutation available. These should be preferred over single-entry mutations as they consume less credit and are generally more efficient.
When using those, you can add an array of nodes (max 500) to send multiple lines of data at once, see below for an example.
mutation{
addCompanies(inputs: [
{node: {
code: "1"
description: "test"
}},
{node: {
code: "2"
description: "test"
}}
{node: {
code: "3"
description: "test"
}}
]) {
edges {
node {
dbId
}
}
}
}
Comma vs line breaks
The examples in these help pages use line breaks between fields, depending on your implementation you might want the queries as flat strings, if so, use commas to separate the fields and escape double quotes, for example:
As a flat string:
"mutation {addSuppliers(inputs: [{node: {code: \"\", description: \"\", "+
"email: \"\", streetAddress: \"\", zipCode: \"\", place: \"\", "+
"country: {code: \"\"}, currency: {code: \"\"}, phone: \"\", "+
"phoneNumber2: \"\", subledgerGroup: {description: \"\"}])"+
"{edges {node {dbId, description}}}"
Instead of:
mutation {
addSuppliers(inputs: [{node: {
code: ""
description: ""
email: ""
streetAddress: ""
zipCode: ""
place: ""
country: {code: ""}
currency: {code: ""}
phone: ""
phoneNumber2: ""
subledgerGroup: {description: ""}
edges {
node {
dbId
description
}
}
}
}
Owner ID and tokens
When generating a token (refer to this documentation for instructions to generate a token), it is associated to the entity in which it has been generated from. Thanks to Xledger hierarchical structure, this token allows access to resources present under that entity, that includes sub-entities. This means that with one token you can potentially access multiple entities. By default, mutations will create resources in the entity the token was generated but most mutations can be instructed to do otherwise using the ownerCode field.
For example, let's consider the following entity structure :
If a token is created for Entity 1, it will allow for creation of suppliers in Entity 1, Entity 1A and Entity 1B (the others entities and the holding won't be accessible by that token.)
If no ownerCode is specified, suppliers will be created in Entity 1 and the leaf entities will be able to see those suppliers. If you were needing to create a supplier only for Entity 1A, you would specify the owner code as shown here :
mutation {
addSuppliers(inputs: [{node: {
code: ""
description: ""
owner:{ownerCode:12345}
edges {
node {
dbId
description
}
}
}
}
To find that ownerCode you can either use the UI to navigate to Administration>Entities or run the following query :
{
entities(last: 100, ownerSet: CURRENT) {
edges {
node {
dbId
description
owner {
code
ownerCode
}
}
}
}
}