Making a Shopify API request from a Custom Pixel

Topic summary

A developer is building a custom Shopify pixel that triggers on checkout_completed to send order data to an ERP system. The core issue: the checkout event only provides an order ID, but the developer needs the purchase order (PO) number.

Key question: Can they make a Shopify API request from within the custom pixel code to fetch the PO number using the order ID before posting to their server?

The developer has shared their JavaScript code, which:

  • Extracts checkout data (line items, pricing, discount codes, billing/shipping addresses)
  • Structures this data into a payload
  • Sends it via fetch() to their upload API
  • Includes a comment marking where they want to insert the API call to retrieve the PO number

Status: The question remains unanswered—no responses yet confirm whether custom pixels can make authenticated Shopify API calls or suggest alternative approaches.

Summarized with AI on November 3. AI used: claude-sonnet-4-5-20250929.

I have created a custom pixel to send order data on “checkout_complete” to an application i’ve developed to upload orders to an erp software. I need to get the PO # of the shopify order that was placed. The checkout_complete hook only returns the order id. Can I make a request to the shopify API to get the PO # using the order id before sending a post request to my server?

Below is my code. Including a comment where I’d like to make the request.

analytics.subscribe('checkout_completed', (event) => {
  const checkout = event.data.checkout;

  const checkoutTotalPrice = checkout.totalPrice?.amount;

  const allDiscountCodes = checkout.discountApplications.map((discount) => {
    if (discount.type === 'DISCOUNT_CODE') {
      return discount.title;
    }
  });

  const firstItem = checkout.lineItems[0];
  const items = [];
  checkout.lineItems.map((item, index) => {
    const newItem = {
        sku: item.variant.sku,
        quantity: item.quantity,
        price: item.finalLinePrice?.amount,
    }
    items[index] = newItem;
  })

 /* items.forEach((item) => {
    console.log(item);
  })*/
  
  const billAdd = {
    firstName: checkout.billingAddress.firstName,
    lastName: checkout.billingAddress.lastName,
    address1: checkout.billingAddress.address1,
    address2: checkout.billingAddress.address2,
    city: checkout.billingAddress.city,
    country: checkout.billingAddress.country,
    province: checkout.billingAddress.province,
    provinceCode: checkout.billingAddress.provinceCode,
    zip: checkout.billingAddress.zip,
    phone: checkout.billingAddress.phone,
};
  const shipAdd = {
    firstName: checkout.shippingAddress.firstName,
    lastName: checkout.shippingAddress.lastName,
    address1: checkout.shippingAddress.address1,
    address2: checkout.shippingAddress.address2,
    city: checkout.shippingAddress.city,
    country: checkout.shippingAddress.country,
    province: checkout.shippingAddress.province,
    provinceCode: checkout.shippingAddress.provinceCode,
    zip: checkout.shippingAddress.zip,
    phone: checkout.shippingAddress.phone,
  };
  const email = checkout.email;
  const orderId = event.data.checkout.order?.id;

  /*make api request to shopify using orderId to get the order PO Number. */

  const payload = {
    event_name: event.name,
    event_data: {
      orderId,
      totalPrice: checkoutTotalPrice,
      discountCodesUsed: allDiscountCodes,
      billingAddress: billAdd,
      shippingAddress: shipAdd,
      email: email,
      items: items,
    },
  };
  
  console.log(payload);
  
  fetch('https://******/uploading-api', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(payload),
    keepalive: true,
  });
});