Hi there. I’m getting an error when trying to run a bulk mutation stating that my store doesn’t have access to the uploaded resource. The resource is being uploaded properly, returning a 201 status code. Additionally, when I check the url, I can view the data. However, it is stating that the store can’t access it despite the id’s being the same between the resourceUrl and the store. I’m programming in NodeJS. Here is some of my code:
async function stageFileUpload(client, jsonlPath) {
const bulk_query = `
mutation {
stagedUploadsCreate(
input:[{
resource: BULK_MUTATION_VARIABLES,
filename: "${jsonlPath}",
mimeType: "text/jsonl",
httpMethod: POST
}]
)
{
userErrors {
field,
message
},
stagedTargets {
url,
resourceUrl,
parameters {
name,
value
}
}
}
}
`
try {
console.log("Staging bulk request...");
const data = await client.request(bulk_query);
console.log("Bulk request staged successfully...");
const form = new FormData();
for(const item of data.data.stagedUploadsCreate.stagedTargets[0].parameters) {
form.append(item.name, item.value)
}
form.append('file', fs.createReadStream(jsonlPath))
console.log("Form prepared and file being uploaded...")
//post request
const res = await axios.post(data.data.stagedUploadsCreate.stagedTargets[0].url, form, {
headers: form.getHeaders(),
maxContentLength: Infinity,
maxBodyLength: Infinity
})
console.log("File uploaded! Status:", res.status);
return data.data.stagedUploadsCreate.stagedTargets[0];
} catch (err) {
console.error("Error adding products:", err.res?.errors || err.message);
return 'error';
}
}
async function addProductsAndVariants(client, staged_upload_path) {
const bulk_query = `
mutation { bulkOperationRunMutation(
mutation: ${JSON.stringify("mutation ($input: ProductInput!) { productCreate(input: $input) { product { id } userErrors { field message } } }")},
stagedUploadPath: ${JSON.stringify(new URL(staged_upload_path).pathname)}) {
bulkOperation {
id
url
status
}
userErrors {
message
field
}
}
}
`
try {
console.log("Adding products...");
const data = await client.request(bulk_query);
console.log('bulk ran successfully');
return data.data;
} catch (err) {
console.error("Error adding products:", err.message);
return 'error';
}
}
The jsonlpath is the path to the file (ex: products.jsonl). Both functions are being called with the same client passed. If anyone knows what the issue is, please let me know! Thanks.