Hi everyone,
I’m using remix template in my app and trying to automatically create a product when the app is installed using the afterAuth hook.
Here is my code:
const shopify = shopifyApp({
apiKey: process.env.SHOPIFY_API_KEY,
apiSecretKey: process.env.SHOPIFY_API_SECRET || "",
apiVersion: ApiVersion.
scopes: process.env.SCOPES?.split(","),
appUrl: process.env.SHOPIFY_APP_URL || "",
authPathPrefix: "/auth",
sessionStorage: new PrismaSessionStorage(prisma),
distribution: AppDistribution.AppStore,
restResources,
future: {
unstable_newEmbeddedAuthStrategy: true,
},
...(process.env.SHOP_CUSTOM_DOMAIN
? { customShopDomains: [process.env.SHOP_CUSTOM_DOMAIN] }
: {}),
hooks: {
afterAuth: async ({ session, admin }) => {
const response = await admin.graphql(
`mutation {
productCreate(input: {
title: "My test product",
productType: "Snowboard",
vendor: "JadedPixel"
}) {
product {
id
title
}
userErrors {
field
message
}
}
}`,
);
},
},
});
To trigger the afterAuth I uninstalled and in then installed the app again. However product was not created.
When I run the same GraphQL query using the Shopify CLI’s GraphiQL, the product is created.
Please, advice what I’m doing wrong?