Order Attribution from admin graphql API

We’re currently using a custom mutation to create orders in our headless Shopify storefront. Since we’re not using Shopify’s native payment gateway and instead integrating Razorpay, our flow is slightly different.

Current Flow:

  1. The user selects a product, and we add it to the cart using the Cart API.
  2. The user completes the payment using Razorpay.
  3. After the payment is confirmed, we create the order via the following GraphQL mutation:
export const createOrderMutation = `
  mutation createOrder($order: OrderCreateOrderInput!, $options: OrderCreateOptionsInput) {
    orderCreate(order: $order, options: $options) {
      order {
        id
        name
        email
        createdAt
        displayFulfillmentStatus
        displayFinancialStatus
        customAttributes {
          key
          value
        }
        totalPriceSet {
          shopMoney {
            amount
            currencyCode
          }
        }
        lineItems(first: 10) {
          nodes {
            id
            name
            quantity
            variant {
              id
              title
              product {
                id
                title
                handle
              }
            }
          }
        }
        shippingAddress {
          firstName
          lastName
          address1
          address2
          city
          province
          country
          zip
          phone
        }
        billingAddress {
          firstName
          lastName
          address1
          address2
          city
          province
          country
          zip
          phone
        }
      }
      userErrors {
        field
        message
      }
    }
  }
`

Issue:

We want to attach marketing metadata to the order — such as UTM source, campaign, medium, etc. However, we haven’t found a way to pass these through the orderCreate mutation.

Question:

Is there a way to include marketing attributes (e.g., UTM parameters) in the orderCreate mutation, perhaps using customAttributes or another field? If not, is there an alternative method to associate such metadata with an order created programmatically outside of Shopify’s checkout flow?

1 Like

Hey @mukesh :waving_hand: - order attributes can definitely work for this, but we do also allow the creation of metafields that should be accepted as inputs on the orderCreate mutation:

https://shopify.dev/docs/api/admin-graphql/latest/mutations/orderCreate#arguments-order.fields.metafields

These metadata wouldn’t be traced through the native reports in the Shopify admin and we don’t support adding UTMs/campaign data for orders created via the API, but these can be set to be accessed by your app/others and could be integrated into custom reports if needed.

Another option you could look into would be the sourceName field, this is traceable for reporting, but is only a single field and does require approval on our end to have it associated with a particular app.

Hope this helps - let me know if I can clarify anything on our end here.