Set unique barcode via Shopify flow/API call

Having issues with the retail barcode labels app creating duplicate barcodes and want to set up a flow to auto generate barcodes when a new variant is created. By setting the barcode of each variant to it’s variantID (legacyresourceID) it would ensure no duplication.

I’m having difficulty getting the API call to run successfully - not sure if this is due to formatting or just improper input. Have tried a few variations and below is my current set up.

Hey @coastalthreadsnc

The issue is with your JSON formatting, the template variables need to be wrapped in quotes since they’re strings in the GraphQL API.

Change it to this:

{
  "productId": "{{product.id}}",
  "variants": [
    {
      "id": "{{productVariant.id}}",
      "barcode": "{{productVariant.legacyResourceId}}"
    }
  ]
}

Without the quotes, the JSON is malformed because the template outputs raw values that break the JSON structure.

Cheers,
Moeed

Worked perfectly - thank you!

Thank you for your reply. I’m glad to hear that the solution worked well for you. If you require any more help, please don’t hesitate to reach out. If you find this information useful, a Like would be greatly appreciated.

Cheers,
Moeed

HI BRO from where did you get admin api key i cant find it

Flows send-admin-api-request action does NOT need an api key as flow handles that because it’s integrated with shopify.
Do not confuse it with the arbitrary send-http-request action that is more external facing.

https://help.shopify.com/en/manual/shopify-flow/reference/actions/send-http-request
To use the shopify api with that specific action , instead of the more internal send-admin-api-request, developers would need to go and create their keys / access tokens which is off topic.
https://help.shopify.com/en/manual/apps/app-types/custom-apps

While "id": "{{ productVariant.id }}" is right in this case, I’d rather recommend
using "id": {{productVariant.id | json }} as it leaves determining the field type to the system.