Apply cart-transform on app install

I have not been able to find anything in the docs explaining how one should go about installing cart-transforms (or really any checkout functions) when an app gets installed. I want to make sure that I get this this right, so I’m reaching out for help.

Based on what I have read in the documentation I would do it this way:

Setup some middleware in my express app that checks if the cart-transform function is installed. If it has not been installed:

//get the id of my function
query {
  shopifyFunctions(first: 25) {
    nodes {
      app {
        title
      }
      id
    }
  }
}


//install it
mutation {
  cartTransformCreate(functionId: "YOUR_FUNCTION_ID_HERE") {
    userErrors {
      field
      message
    }
  }
}
  1. Do I have to get the ID of my function on each store? Or does my function ID never change?
  2. Do I need to worry about updating my function through the API whenever I deploy a new update to it with shopify app deploy?
1 Like

Hey you :heart_eyes:

I’ve always just ran the cartTransformCreate manually in the GraphiQL Explorer app, so I’m not 100% sure if theres any noticeable changes doing it from the app.

However I’ve never noticed the function ID change after creation, but it do seem to be generated on creation, so it will differ from store to store.

Never noticed any problems deployed app updates. You dont have to create the function again.


Is your usecase gonna be a public app hence the need of automating the creation? Or just for some template code helping you? :smiley:

Hi Curzey!

Lovely to see you on here :heart_eyes:

Yes this is for a public app thats already in distribution, so manually running the mutation is not viable in this case.

I was hoping the function ID was the same regardless of what store its on :upside_down_face: So if that is the case, I would have to query to get the id.

  shopifyFunctions(first: 25) {
    nodes {
      app {
        title
      }
      id
    }
  }

But doing it by getting the first:25 and then manually comparing the app title, to get make sure it is my function seems yucky, any recommendations?

1 Like

Likewise :heart_eyes:

Well, I guess I take everything back. I just tested the shopifyFunctions query on two stores running the same unpublished app with cartTransform functions. They both return the same ID.

I asked the .dev Assistant on the API docs which actually says that the ID is constant. Got me taking a look, and found it in the partners app dashboard

.dev Assitant reply:

The ID of a Shopify Function remains identical across multiple stores because it is tied to the specific function instance created by the app developer. This ID is generated when the function is created and deployed as part of the app. It is not store-specific but rather app-specific, meaning that the same function deployed across multiple stores will retain its original ID.

This behavior ensures consistency and allows the app to reference the same function logic across different stores. The ID is derived from the app’s deployment process and is used to uniquely identify the function within the Shopify ecosystem.

For more details on how Shopify Functions work and their lifecycle, you can refer to the Shopify Functions documentation.

1 Like