So I have created an app which basicaly works great . Only issue is when I make any changes in the app . The App proxy requests do not work until I have reopend the app in the store . So even if I make any changes then it stops the app proxy admin api requests to work . I believe I need to use Session token . But unforfunately I dont know how to implement that .
Below is Sample Code of what I am using
Any help would be greatly appreciated
import { json } from "@remix-run/node";
import { authenticate } from "../shopify.server";
async function getCustomerMetafields(admin, customerId) {
const response = await admin.graphql(
`#graphql
query CustomerMetafields($ownerId: ID!) {
customer(id: $ownerId) {
metafields(first: 3, namespace: "pwc_customer_wishlist") {
edges {
node {
namespace
key
value
}
}
}
}
}`,
{
variables: { ownerId: `gid://shopify/Customer/${customerId}` },
},
);
const data = await response.json();
return data?.data?.customer?.metafields?.edges[0]?.node?.value || "";
}
export async function loader({ request }) {
const { admin } = await authenticate.public.appProxy(request);
const url = new URL(request.url);
const customerId = url.searchParams.get("customerId");
if (!customerId) {
return json({ error: "Missing customerId parameter" }, { status: 400 });
}
const productIds = await getCustomerMetafields(admin, customerId);
return json({ wishlist: productIds.split(",") });
}