Hello everyone, we are working on our first shopify app and we are stuck!
We created a simple Shopify React app using Shopify CLI: shopify create
We need to read and write shop metafields. From Admin API or GraphQL.
Read the list of Metafields - after app opened.
Add new metafield - on button click.
How we can do these actions? Which data do we need(access token, or mutations) for these requests? For example, our metafield must contain three fields:
name: 'Some name',
description: 'Some description',
url: 'Some url'
All the relevant information you need can be found on the docs.
However, you shouldn't do this from React. What you ought to do is:
1. Create your own REST API (or Graphql server, whatever it is).
It will serve as your connector between the front end (react) and the Shopify's API.
2. In your REST API, create a CRUD to connect with the Shopify API metafields. So you'll have something like ngrok.com/metafield which you can do a GET, POST, UPDATE and DELETE requests.
3. Make a POST request to your own REST API, your REST API will do a POST to the Shopify API and then you can return whatever you wish, like the created metafield for example.
That's about it - the "how to do it" is more syntax/language related issues which are not essentially part of the Shopify's API.
Hope it helps.