Originally posted by **kathir-arizon** October 14, 2024
I tried to fetch the metafields based on the product ID but I am always getting the product as null when I run the same query in the playground it's working as expected.
Could you please let me know if anything wrong with my code or missing something?
```ts
const ProductMetaFieldsQuery = graphql(
`
query ProductMetaFieldsQuery($entityId: Int!, $nameSpace: String!) {
site {
product(entityId: $entityId) {
metafields(namespace: $nameSpace, first: 50) {
edges {
cursor
node {
entityId
id
key
value
}
}
pageInfo {
endCursor
hasNextPage
startCursor
hasPreviousPage
}
}
}
}
}`
);
export const getProductMetaFields = async (entityId: number, nameSpace: string) => {
console.log('========entityId=======', entityId);
const customerId = await getSessionCustomerId();
const { data } = await client.fetch({
document: ProductMetaFieldsQuery,
variables: {entityId: entityId, nameSpace: nameSpace}
});
console.log('========data=======', data);
};
```
Response in CLI:
```
========entityId======= 41110
========data======= { site: { product: null } }
```
Discussed in https://github.com/bigcommerce/catalyst/discussions/1455