Unexpected file structure - expected JSONL

I want to perform a bulk mutation in my shop at regular intervals. For this, I am using an example from the documentation provided here: Shopify Bulk Operations Documentation.

When I execute the code, everything works fine until the step where I run the bulkOperationRunMutation. At this step, the data object returns the following error message:

{
  "bulkOperationRunMutation": {
    "bulkOperation": null,
    "userErrors": [
        {
          "message": "Unexpected file structure - expected JSONL",
          "field": null
        }
      ]
  }
}

What am I doing wrong, or what could be the issue?

Below is my code and the content of the JSONL file.

{ "input": { "title": "Sweet new snowboard 1", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 2", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 3", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 4", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 5", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 6", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 7", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 8", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 9", "productType": "Snowboard", "vendor": "JadedPixel" } }
{ "input": { "title": "Sweet new snowboard 10", "productType": "Snowboard", "vendor": "JadedPixel" } }
import { createAdminApiClient } from "@shopify/admin-api-client";
import * as fs from "fs";

// Authentication
const client = createAdminApiClient({
  storeDomain: "myshop.myshopify.com",
  apiVersion: "2024-04",
  accessToken: "myAccessToken",
});

const createUploadUrlMutation = `
    mutation {
    stagedUploadsCreate(input:{
        resource: BULK_MUTATION_VARIABLES,
        filename: "bulk_op_vars",
        mimeType: "text/jsonl",
        httpMethod: POST
    }){
        userErrors{
        field,
        message
        },
        stagedTargets{
        url,
        resourceUrl,
        parameters {
            name,
            value
        }
        }
    }
    }
`;

const createUploadUrlMutationResult = await client.request(
  createUploadUrlMutation
);

console.log(createUploadUrlMutationResult);

const url =
  createUploadUrlMutationResult?.data?.stagedUploadsCreate.stagedTargets[0].url;

const formData = new FormData();

createUploadUrlMutationResult?.data?.stagedUploadsCreate.stagedTargets[0].parameters.forEach(
  (param) => {
    formData.append(param.name, param.value);
  }
);

formData.append("file", fs.createReadStream("./docs-test.jsonl"));

// Upload Update File
const uploadUrlResult = await fetch(url, {
  method: "POST",
  body: formData,
});

const resultXml = await uploadUrlResult.text();

const regex = /

I have found the solution.

Instead of uploading the file as follows:

formData.append(‘file’, fs.createReadStream(‘./docs-test.jsonl’));

You have to upload the file like this:

const buffer = fs.readFileSync("./bulk_op_vars.jsonl");
const blob = new Blob([buffer]);
const myFile = new File([blob], "bulk_op_vars.jsonl");

formData.append("file", myFile, "bulk_op_vars.jsonl");
1 Like