Exposing Metafileds to Storefront API

etn207
New Member
4 0 0

Hello,

Sorry for the rather basic question. I'm new to GraphQL and the Storefront API. I'm trying to expose some metafields. If i'm reading the docs correctly, I need to first expose them (one time) to then be able to request. I'm having no trouble with basic storefront requests.

Below is what my request looks like. Any thoughts on why this isn't working? 

Very much appreciated and again sorry for such a basic question.

best

Eric

 

 

function apiSetup () {
  return fetch('https://apbookserlin.myshopify.com/admin/api/2021-04/graphql.json', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'X-Shopify-Access-Token': {ADMIN_API_KEY}
    },
    body: JSON.stringify({
      query: `
      mutation($input: MetafieldStorefrontVisibilityInput!) {
        metafieldStorefrontVisibilityCreate(
          input: $input
        ) {
          metafieldStorefrontVisibility {
            id
          }
          userErrors {
            field
            message
          }
        }
      }
        `,
      variables: {
        "input": {
          "namespace": "event",
          "key": "time",
          "ownerType": "ARTICLE"
        }
      },
    }),
  }).then(response => response.json());
}

apiSetup().then(response => {
  console.log(response);
 });

 

0 Likes
etn207
New Member
4 0 0

I was able to figure this out.

The endpoint should be:

/admin/api/graphql.json

The headers should be as follows:

X-Shopify-Access-Token: [Set this to you password field not the api key]

 

0 Likes