when creating draft order with graphql with the following function 400 error encountered
async function createBulkOrder(
locationId,
locationName,
monthName,
year
) {
const lineItems = [
{
variantId: "gid://shopify/ProductVariant/42726908887213",
quantity: 2,
},
{
variantId: "gid://shopify/ProductVariant/42726908919981",
quantity: 3,
},
{
variantId: "gid://shopify/ProductVariant/43314902728877",
quantity: 4,
},
];
if (!lineItems.length) {
console.error("Error: lineItems array is empty or missing");
return;
}
const createdVariables = {
input: {
lineItems: lineItems,
tags: ["barcelona-warehouse", `auto-generated`, `$jan-2025`],
note: `Auto-generated draft order at ${locationName}. Month: ${monthName} ${year}. Location ID: ${locationId}`,
},
};
console.log(
"Variables being sent:",
JSON.stringify(createdVariables, null, 2)
);
const mutation = `mutation draftOrderCreate($input: DraftOrderInput!) {
draftOrderCreate(input: $input) {
draftOrder {
id
name
lineItems(first: 150) {
nodes {
id
quantity
variant {
id
}
}
}
}
userErrors {
field
message
}
}
}`;
try {
const response = await shopify.graphql({
query: mutation,
variables: createdVariables,
});
console.log("Full GraphQL Response:", JSON.stringify(response, null, 2));
// Rest of the success handling logic
// ...
} catch (error) {
console.error("Error creating order:", error.message);
console.error("Error stack trace:", error.stack);
// Extract any available error information
if (error.body) {
console.error("Error body:", typeof error.body === 'string' ? error.body : JSON.stringify(error.body, null, 2));
}
if (error.statusCode) {
console.error("Error status code:", error.statusCode);
}
if (error.statusMessage) {
console.error("Error status message:", error.statusMessage);
}
if (error.headers) {
console.error("Error headers:", error.headers);
}
// If there are GraphQL specific errors
if (error.graphQLErrors) {
console.error("GraphQL Errors:", JSON.stringify(error.graphQLErrors, null, 2));
}
// If there are network errors
if (error.networkError) {
console.error("Network Error:", error.networkError);
}
// Log the entire error object for inspection
console.error("Full error object keys:", Object.keys(error));
throw error; // Rethrow to handle it in higher-level code
}
}
this is the error logs
Error creating order: Response code 400 (Bad Request)
Error stack trace: HTTPError: Response code 400 (Bad Request)
at Request.<anonymous> (/Users/rajib/Desktop/Project/Web/clients/linda/linda-shopify-excel-integration-12-02-25/node_modules/got/dist/source/as-promise/index.js:118:42)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Full error object keys: [ 'name', 'code', 'timings' ]
node:internal/process/esm_loader:40
internalBinding('errors').triggerUncaughtException(
^
HTTPError: Response code 400 (Bad Request)
at Request.<anonymous> (/Users/rajib/Desktop/Project/Web/clients/linda/linda-shopify-excel-integration-12-02-25/node_modules/got/dist/source/as-promise/index.js:118:42)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'ERR_NON_2XX_3XX_RESPONSE',
timings: {
start: 1741396317990,
socket: 1741396317991,
lookup: 1741396317998,
connect: 1741396318009,
secureConnect: 1741396318027,
upload: 1741396318027,
response: 1741396318490,
end: 1741396318496,
error: undefined,
abort: undefined,
phases: {
wait: 1,
dns: 7,
tcp: 11,
tls: 18,
request: 0,
firstByte: 463,
download: 6,
total: 506
}
}
}
i am using shopify-api-node package and api version is 2024-10
please help