Note: You can download a postman example of the below queries in this article's attachments.
Unicity Check
When creating or updating projects, the Project Code is usually used as the unique identifier. Because of this, it is good practice to check for existence before creating a new project.
To do so, you can run the following query :
{
projects(last: 10, filter: {code: "enter project 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": {
"projects": {
"edges": null
}
}
}
If the answer is as follows, it means the project exists and you can proceed to update it :
{
"data": {
"projects": {
"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.
Project creation
Here is an example of a project creation, mandatory fields are code and description only, use the rest according to your needs.
mutation {
addProjects(inputs: [{node: {
code: "123412341234"
description: "test"
fromDate:"2022-01-01"
toDate:"2023-01-01"
billable:true
fundProject:true
timesheetEntry:true
#glObject1:{code:""}
#glObject2:{code:""}
#glObject3:{code:""}
#glObject4:{code:""}
#glObject5:{code:""}
#xgl:{code:""}
}}]) {
edges {
node {
dbId
}
}
}
}
Note: If you need to raise invoices against the project, make sure billable is true and the invoice date is within from and to dates.
Project update
Here is an example of a project update, dbId is returned by the existence check, use this to specify which project to update.
mutation {
updateProjects(inputs: [{node: {
dbId:28630394
code: "123412341234"
description: "test"
fromDate:"2022-01-01"
toDate:"2023-01-01"
billable:true
fundProject:true
timesheetEntry:true
#glObject1:{code:""}
#glObject2:{code:""}
#glObject3:{code:""}
#glObject4:{code:""}
#glObject5:{code:""}
#xgl:{code:""}
}}]) {
edges {
node {
dbId
}
}
}
}