[ADMIN API] How can i use admin api in hydrogen #580
-
I had a hydrogen 2 app running and I want to access the admin via the app, how can I config it? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
In the |
Beta Was this translation helpful? Give feedback.
-
I configured the Admin API client as follows by referring to the shopify api repo. // ~/lib/shopify.ts
import {shopifyApi, LATEST_API_VERSION} from '@shopify/shopify-api';
import {restResources} from '@shopify/shopify-api/rest/admin/2023-01';
import '@shopify/shopify-api/adapters/cf-worker';
export const shopify = shopifyApi({
apiKey: '[YOUR KEY]',
apiSecretKey: '[YOUR KEY],
apiVersion: LATEST_API_VERSION,
isCustomStoreApp: true,
scopes: [],
isEmbeddedApp: false,
hostName: `[YOUR_SHOP_URL]`,
restResources,
}); After that, I retrieved the data after importing the admin client from the loader. or Pass it with context import {shopify} from '~/lib/shopify'
export async function loader() {
const email = '[EMAIL]'
const session = shopify.session.customAppSession('[YOUR_SHOP_URL]');
const {customers} = await shopify.rest.Customer.search({
session,
query: `email:${email}`,
});
}); |
Beta Was this translation helpful? Give feedback.
-
This solution doesn't work anymore, there was a repos that had example, but I can't find it? |
Beta Was this translation helpful? Give feedback.
I configured the Admin API client as follows by referring to the shopify api repo.
After that, I retrieved the data after importing the admin client from the loader. or Pass it with context