Order Line item without product id and with product_exists = false

I’m retrieving orders via the GraphQL API to build pick lists.
Some order line items return with a product that has a name but no product id or variant id. (I pasted an exemple of GraphQL output below)

To try to understand what’s happening, I requested the same Order via the Rest API.
When I do that, I get a field called product_exists that is systematically false when the line item doesn’t have any product information but the name. (I copied a Rest API response below)

There is no trace of the product_exists field in the documentation and I can’t find anything related in the GraphQL documentation. I need a id for the product of these line items to handle them.

What can I do ?

Exemple of GraphQL response

{
  "code": 200,
  "headers": {

  },
  "body": {
    "data": {
      "nodes": [
        {
          "id": "gid://shopify/Order/5855658705040",
          "name": "#66430",
          "lineItems": {
            "nodes": [
              {
                "id": "gid://shopify/LineItem/14685259890842",
                "name": "Headlamp Strap",
                "currentQuantity": 1,
                "sku": null,
                "variantTitle": null,
                "vendor": "",
                "image": null,
                "product": null,
                "variant": null
              }
            ],
            "pageInfo": {
              "hasNextPage": false,
              "endCursor": "eyJsYXN0X2lkIjasdfasfOTg5MDg0MSwibGFzdF92YWx1ZSI6MTQ2ODUyNTk4OTA4NDF9"
            }
          }
        }
      ]
    },
    "extensions": {
      "cost": {
        "requestedQueryCost": 7,
        "actualQueryCost": 7,
        "throttleStatus": {
          "maximumAvailable": 20000,
          "currentlyAvailable": 19993,
          "restoreRate": 1000
        }
      }
    }
  },
  "prev_page_info": null,
  "next_page_info": null,
  "api_call_limit": null,
  "retry_request_after": null
}

Exemple of Rest response

{
  "line_items": [
    {
      "id": 14685259890841,
      "admin_graphql_api_id": "gid://shopify/LineItem/14685259890842",
      "attributed_staffs": [],
      "current_quantity": 1,
      "fulfillable_quantity": 1,
      "fulfillment_service": "manual",
      "fulfillment_status": null,
      "gift_card": false,
      "grams": 0,
      "name": "Headlamp Strap",
      "pre_tax_price": "6.00",
      "pre_tax_price_set": {
        "shop_money": {
          "amount": "6.00",
          "currency_code": "USD"
        },
        "presentment_money": {
          "amount": "6.00",
          "currency_code": "USD"
        }
      },
      "price": "6.00",
      "price_set": {
        "shop_money": {
          "amount": "6.00",
          "currency_code": "USD"
        },
        "presentment_money": {
          "amount": "6.00",
          "currency_code": "USD"
        }
      },
      "product_exists": false,
      "product_id": null,
      "properties": [],
      "quantity": 1,
      "requires_shipping": true,
      "sku": null,
      "taxable": true,
      "title": "Headlamp Strap",
      "total_discount": "0.00",
      "total_discount_set": {
        "shop_money": {
          "amount": "0.00",
          "currency_code": "USD"
        },
        "presentment_money": {
          "amount": "0.00",
          "currency_code": "USD"
        }
      },
      "variant_id": null,
      "variant_inventory_management": null,
      "variant_title": null,
      "vendor": "",
      "tax_lines": [],
      "duties": [],
      "discount_allocations": []
    }
  ],
 ...
}
1 Like

Hey @Antonio :waving_hand: - thanks for reaching out here. Usually, when we see a line item pop up without an associated variant or product ID, the most common reason for this is if a product was deleted or if the line item is a custom product that was created only for that order (more info on this here).

You are right that there isn’t a direct way to check if the product exists in GraphQL, but if you did need to build a workaround for this using GraphQL, you could build some logic into your integration to run a query based on the name of the product when it encounters line items without associated product/variant IDs by running a products query (using the “name” value in the title search argument : products - GraphQL Admin).

Just to make sure I’m giving the best recommendation here though, can you let me know how you’re handling the “empty” products? Just want to see if we can offer a better workaround if possible - hope this helps a bit!

Hi @Alan_G,

Thank you for your response. Please find below what I think my problem is and what I need to solve it.

Daily I have exemples of the case, consequently I’m pretty sur that they are not deleted products.

As well, I don’t know if there is a way for shops to let their clients to add custom product to orders but it looks like that. Some shops have multiple orders containing line items of product without product_id/variant_id.

What I need

What I need is a way to uniquely identify those products without product_id/variant_id to be able to count them cross orders and list them gathered together.

Exemple with two orders containing the custom product named P

Order A → Line Item A1 → CustomProduct P with quantity 2
Order B → Line Item B1 → CustomProduct P with quantity 3

From these two Orders I need to create one pick list item like below but I don’t have a unique id for the id.

Name: P / quantity: 5 / Orders: A,B / id: ???

The only possibility that I see is to use the custom product name as an identifier in some way. What do you think about this solution ?

I wonder if there is another alternative more systematic then the only solution that I see:

The only possibility that I see is to use the custom product name as an identifier in some way.

I’m making my question jump a last time, trying to reach someone experiencing what I do experience.

Hi @Alan_G,

What I should expect as a response when I run a GraphQL product query ? No product at all?

You can find below what I did. The response has no product. As a complimentary information, when I do the same request with an existing product name it returns the product

client = ShopifyAPI::Clients::Graphql::Admin.new(
  session: sess
)

query = <<~QUERY
  query {
    products(first:1, query:"title:Farmer's Choice Box (All Organic) - Home Delivery") {
      edges {
        node {
          id
          title
          handle
        }
        cursor
      }
      pageInfo {
        hasNextPage
      }
    }
  }
QUERY

response = client.query(query: query)

irb(main):053:0> response.body
=> 
{"data"=>{"products"=>{"edges"=>[], "pageInfo"=>{"hasNextPage"=>false}}},
 "extensions"=>{"cost"=>{"requestedQueryCost"=>3, "actualQueryCost"=>2, "throttleStatus"=>{"maximumAvailable"=>2000.0, "currentlyAvailable"=>1998, "restoreRate"=>100.0}}}}

Hey @Antonio - thanks for following up and the ping here. You’re correct - generally, if the product is a custom line item or a deleted product, you would expect it not to show up in that query.

One way that you could narrow down if a product was a custom line item or a deleted product would be to use the orders/create webhook topic: Webhooks

This would mean that you’d have to set up a webhook listening server, but what would happen is that this webhoook would trigger whenever there’s a new order created and would include the product/variant IDs of the line items in its data payload.

If you then query the order in the future and see an “empty”/“missing” line item, you could cross reference it against the data in the original webhook payload data for when the order was created to check if it is a custom line item or a deleted product. If the original webhook data has product/variant information, you would know that it is a deleted product being referenced in the line item rather than a custom product.

Hope this helps/makes sense - let me know if I can clarify as always here!

From my app data analysis, it’s all the time (almost) custom line items.

It seems different then what you shared: merchants use this feature a lot to sell product on their stores. I don’t know what the benefits to do that for them, but I have many orders daily with this kind of line items.

I suppose that I’ll have to follow the only way to fix that for me by using the name of the custom product name as identifier. They definitely want to pick these custom items in their warehouse.