Bulk Query Operation returning null for node

dsegal_maze
Shopify Partner
2 0 1
Im using the Graphql Admin API along with Webhooks in a node.js app to process bulk queries. I am able to successfully create the mutation to start the BulkOperation, returning an object with the process id and status, with no entries in the userErrors key.  When my app's webhook enpoint recieves the `BULK_OPERATIONS_FINISH` request, I get back the expected payload, with the same gid as in the original mutation return value. The problem is that querying for that node by id returns { node: null }.

Worth noting, I'm aware that if your query returns no items, then the url will be null but thats not whats happening here - the entire node is null, not just the url. 

To troubleshoot I used the GraphiQL test app on my developments store and ran the exact same queries and mutation as my app and was able to retrieve the node with all of the expected attributes like the url to the JSONL file.

Here's the code for creating the BulkOperation:

 

const session = await Shopify.Utils.loadCurrentSession(req, res);
const { shop, accessToken } = session;
const client = new Shopify.Clients.Graphql(shop, accessToken);

const bulkQueryVariables = {
  query: `{
    customers {
      edges {
        node {
          id
          firstName
          lastName
          email
          defaultAddress {
            id
            firstName
            lastName
            address1
            address2
            city
            province
            provinceCode
            country
            countryCodeV2
            zip
          }
        }
      }
    }
  }`
}

const bulkQuery = `
  mutation($query: String!) {
    bulkOperationRunQuery(query: $query) {
      bulkOperation {
        id
        status
      }
      userErrors {
        field
        message
      }
    }
  }`;

const { body } = await client.query({
  data: {
    query: bulkQuery,
    variables: bulkQueryVariables
  }
});

if (body.userErrors) {
  // userErrors is empty, this block never runs
  console.log(error("BULK_QUERY_ERROR"), body.userErrors);
  res.status(500).json({ status: 500, error: body.userErrors });
}

console.log(info("BULK_QUERY_PROCESSED"));
console.dir(body.data);
/* Returns:
{
   bulkOperationRunQuery: {
     bulkOperation: {
       id: 'gid://shopify/BulkOperation/1000007131997',
       status: 'CREATED'
    },
    userErrors: []
  }
}
/*

 

 

Querying for the returned id returns null in my app as well as GraphiQL. I've also tried many different queries, including the simple products query shown in this tutorial with the exact formatting (triple quote marks and no variables).  Just for the sake of being thorough, here's my app code that handles the webhook request:

 

import Shopify from "@shopify/shopify-api";
import { info, success, error } from "../../utils/logger";

export const bulkHandler = async (shop, reqBody) => {
  const session = await Shopify.Utils.loadOfflineSession(shop);
  const body = JSON.parse(reqBody);
  
  const { accessToken } = session
  const { admin_graphql_api_id } = body;

  const client = new Shopify.Clients.Graphql(shop, accessToken)

  console.log(info('BULK_HANDLER_BODY'))
  console.log(body)

  const query = `{
    node(id: "${admin_graphql_api_id}") {
      ... on BulkOperation {
        url
        partialDataUrl
      }
    }
  }`

  console.log(info("BULK_GRAPH_QUERY"));
  console.log(query);

  const res = await client.query({
    data: {query}
  })

  const { data } = res.body
  console.log(info('BULK_GRAPH_ATTEMPT'), data)
  // Returns { node: null }
};

 

 

What could be the reason that the BulkOperation nodes created by my app are not accessible, but not when using the GraphiQL app? I made sure that my app has proper read and write scopes for products and customers (the only two bulk queries I've tried)

Replies 12 (12)

Schmidtc63
Shopify Partner
90 13 23

Did you ever get this figured out? I'm having the same issue.

Schmidtc63
Shopify Partner
90 13 23

Ok. I figured this out.

 

If you use the shopify-graphiql-app to create your webhook, the webhook is created under different credentials than the other webhooks for your store/custom app. 
You have to create the webhook through GraphQL using the credentials of your other webhooks, which most likely means just submitting the webhook creation query as you do your other GraphQL queries.

syedusama0786
Shopify Partner
42 2 10

@Schmidtc63 Hey Bro !
I need Help.
I am doing the bulkOperationRunMutation for productCreate but i got null object in return. Do you Know anything about it?

Schmidtc63
Shopify Partner
90 13 23

I don't off hand. However... I bet we can figure this out. 

 

Post your query and we'll take it from there. 

syedusama0786
Shopify Partner
42 2 10

@Schmidtc63 Thanks for your replay!
i posted my query here:
https://community.shopify.com/c/shopify-apps/bulkoperation-response-is-null-when-creating-products-i...
but I didn't get any solution yet.

ShopifyDevSup
Shopify Staff
1440 235 490

Hey @syedusama0786 - can you share the response body you're receiving from the API call that returns the null value for the bulk operation? Are you just receiving a null value for the bulk operation or are you seeing any error messages returned? 

Hope to hear from you soon - happy to help out with this. 

Al | Shopify Developer Support 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

syedusama0786
Shopify Partner
42 2 10

Thank You So much for your response I solve this issue!

nahtE
Shopify Partner
4 0 2

Hi there,

 

How did you resolve this? 

 

I'm running a bulk mutation for productCreate for 1000 products at a time, but I have noticed that it will either miss a product or two, or it when I go to the returned URL for the jsonl file, it has null for all my products. 

 

As it doesn't give me any errors or any information, I'm unsure how I'm meant to diagnose why it doesn't upload the products. 

 

Here is a screenshot (since jsonl files aren't supported for some reason) of the file...

nahtE_0-1675372593129.png

 

As you can see, only one product uploaded out of the 1000, and it's missing all its fields other than the title and descriptionHtml. 

 

Thanks in advance.

syedusama0786
Shopify Partner
42 2 10

@nahtE First of all sorry for the late reply!

I think you did something wrong when you create a JSONL file for your product.
My Query is working fine but I got an issue in the bulk query it skip some of my products.
but in the response JSONL file, it shows me all the products.

nahtE
Shopify Partner
4 0 2

No I don't believe I did anything wrong, as its entirely random and different products each time. Another perk of Shopify's absolute shit API with garbage documentation. 

syedusama0786
Shopify Partner
42 2 10

@nahtE Hey!😅
Show me your code probably it will help you after I analyze your code.

makasanas
Shopify Partner
22 0 3

@Schmidtc63 @ShopifyDevSup 

I am also in same kind of issue like @dsegal_maze mention. what I figure out so far. Here is my query 

query {
  node(id: "gid://shopify/BulkOperation/3782671040662") {
    ... on BulkOperation {
      url
      partialDataUrl
    }
  }
}


Right I use shopify node api library shopify-api 7.1.0.
Here is problem when I try access same query with online session it's working fine but when I try to fetch using offline session, I am getting same 
"node": null as response. 

can tell what can be problem here?