Using requestDraftOrders to purchase for menus via the API
You can use Galley's purchasing logic for menus directly in the API. To do so, use requestDraftOrders
. This mutation takes a set of menus and, through an async process, generates a set of draft orders. A draft order can be thought of as a purchase order before it is finalized. These draft orders are what comprise Galley purchasing guides.
To kick off this process, you will pass the IDs of the menus that you would like to purchase for to requestDraftOrders
. You should request a jobId
in the response. You will this job to find the draft orders once they are created. Additionally, the customization options that are possible through Galley's purchasing process can be passed in the input as options
.
Query
mutation requestOrders ($input:RequestDraftOrdersInput!){
requestDraftOrders(input:$input){
jobId
}
}
{
"input": {
"menuIds":["<your menu ids>"]
}
}
As mentioned above, requestDraftOrders
is an async process. The job that it kicks off is where we will find the status of that process and get our draft orders when they're ready (which will be returned in the job's body).
Query
query checkJob ($jobId:String!){
viewer{
company{
job(id:$jobId){
status
body
}
}
}
}
Now, you can pass the draftIds
from the job's body to draftOrderConnection
as ids
.
Query
query draftOrders(
$ids: [String!]
$paginationOptions: DraftOrdersConnectionPaginationOptions!
) {
viewer {
draftOrdersConnection(ids: $ids, paginationOptions: $paginationOptions) {
edges {
node {
id
destinationLocation {
id
name
}
vendor {
id
name
}
draftOrderItems {
vendorItem {
id
name
}
requiredQuantity
requiredPurchaseableUnit {
id
name
}
calculatedOrderQuantity
calculatedOrderUnit {
id
name
}
}
}
}
}
}
}
Those draft orders can either be used as is (such as a purchasing guide) or passed to upsertPurchaseOrder
if you would like to create Galley purchase orders.
Note: when you execute draft orders there won't be a purchasing guide available in your purchasing guide catalog