Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Barcode in Webhook or Order API

Solved

Barcode in Webhook or Order API

manuraj-tryzens
Shopify Partner
3 0 0

Hello Shopify Team,

 

We are trying to fetch the "barcode" from the "orders/paid" and "orders/updated" webhook response. We couldn't find the barcode from the API responses as well the Shopify documentation.

 

Is there any way to get the product barcode in the line items section of the Shopify Order API or Shopify Webhooks?

Accepted Solution (1)

Liam
Community Manager
3108 344 899

This is an accepted solution.

Webhooks for orders don't appear to have a field for barcodes, but you should be able to use the GraphQL API to query the `order` object to get line items's barcodes like this:

 

{
  order(id: "gid://shopify/Order/5402053902550") {
    id
    lineItems(first: 10) {
      edges {
        node {
          id
          variant {
            id
            barcode
          }
        }
      }
    }
  }
}

 

When I tested this out it returned a test barcode that I added:

{
  "data": {
    "order": {
      "id": "gid://shopify/Order/5402053902550",
      "lineItems": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/LineItem/13419036344534",
              "variant": {
                "id": "gid://shopify/ProductVariant/44835344515286",
                "barcode": "234567890-"
              }
            }
          }
        ]
      }
    }
  },

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

View solution in original post

Reply 1 (1)

Liam
Community Manager
3108 344 899

This is an accepted solution.

Webhooks for orders don't appear to have a field for barcodes, but you should be able to use the GraphQL API to query the `order` object to get line items's barcodes like this:

 

{
  order(id: "gid://shopify/Order/5402053902550") {
    id
    lineItems(first: 10) {
      edges {
        node {
          id
          variant {
            id
            barcode
          }
        }
      }
    }
  }
}

 

When I tested this out it returned a test barcode that I added:

{
  "data": {
    "order": {
      "id": "gid://shopify/Order/5402053902550",
      "lineItems": {
        "edges": [
          {
            "node": {
              "id": "gid://shopify/LineItem/13419036344534",
              "variant": {
                "id": "gid://shopify/ProductVariant/44835344515286",
                "barcode": "234567890-"
              }
            }
          }
        ]
      }
    }
  },

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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