I am trying to create a flow that automatically deletes any draft order tagged as “Stale”. I have a flow set up and working that tags draft orders as “Stale” 48 hours after they’re created. So far, my flow is as follows:
When I attempt to run it, however, I keep getting this error at the Send Admin API request stage: “Exception: Mutation had errors: “Variable $input of type DraftOrderDeleteInput! was provided invalid value””.
How should I edit the code/flow so it automatically deletes stale draft orders?
Thank you for your help!!
Can you show a screenshot of the draftOrderDelete mutation step?
You’re getting that error because the API expects a specific GraphQL ID format (gid://shopify/DraftOrder/12345), not just the numeric ID. Or your JSON variables block is malformed.
In Flow’s “Send Admin API request” action, it’s way easier to just use Liquid directly in the mutation instead of passing separate variables.
Try pasting exactly this into the query box:
graphql
mutation {
draftOrderDelete(input: {id: "{{ draftOrder.adminGraphqlApiId }}"}) {
deletedId
userErrors {
message
}
}
}
I use this exact setup on my store to clear out old wholesale drafts. Just make sure your Flow trigger actually provides the draftOrder object so that Liquid variable populates correctly.
Thanks for your reply! Here’s what I’m seeing:
I meant the actual step you created, but that’s fine. Here are the steps as they should work:
{
"input": {
"id": "{{ getDraftOrderDataForeachitem.id }}"
}
}
Make sure the ID is the sort by in the Get Draft Order Data. If you’re still getting an error, I’d ask Sidekick to do it. It does have access to create and modify, even though sometimes it will say it doesn’t.
Just in case, here is the documentation for the API call which shows how the input should look and what data it expects – see the “Examples” on the right:
Just tested in my store – Flow gets full IDs, so below is likely not needed, but check your Flow logs.
As already mentioned above, mutation needs a full gid://shopify/... ID while Flow may (in some cases) internally use a numeric legacyId which matches the last part of the full id:
{
"id": "gid://shopify/DraftOrder/162487337014",
"legacyResourceId": "162487337014"
}
So if input suggested by Maximus above would not work, you may need to construct full ID yourself:
{
"input": {
"id": "gid://shopify/DraftOrder/{{- getDraftOrderDataForeachitem.id -}}"
}
}
That code worked, I cannot thank you enough!!