iOS and Android Buy SDK Metafield

ChuckBlake
Tourist
6 0 0

Hi, We got an issues querying and mutating the data for metafields via iOS and Android Buy SDK. There seems to be no documentation on how to do this.

For example, we need to create a custom field for customer called "favorite color" and require to store this field to be stored by Shopify metafields for each customer. We need to both query and mutate this field via the Android and iOS app we are creating for this store. 

If anyone can assist would be greatly appreciated. 

Replies 6 (6)

vix
Shopify Staff
540 103 121

Hi @ChuckBlake 

With the Storefront API, you can retrieve metafields but not create or update them. If you want to create, update, or delete metafields, then you need to use theGraphQL Admin APIor theREST Admin API.

From here: https://shopify.dev/tutorials/retrieve-metafields-with-storefront-api - so if you need to update them that will need to be server side with the admin API

 

To learn more visit the Shopify Help Center or the Community Blog.

ChuckBlake
Tourist
6 0 0

Hi @vix 

As far as i can see to add a meta fields to a user we need to use admin/customers/{userID}.json service. We tried to use this service to add meta fields to a user and we were able to do it from Postman. 

Below is the service that we have used.

URL: https://[API_KEY]:[PASSWORD_OF_PRIVATE_APP]@[storename]/admin/customers/[userID].json

Request Type: PUT

Headers

Content-Type: application/json
Content-Length: <calculated when request is sent>
Host: <calculated when request is sent>
User-Agent: PostmanRuntime/7.26.5
Accept: */*
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
 

Post parameters: {"customer":{"id":"thisIsUserID","metafields":[{"key":"userDob","namespace":"userDob","value":"2/January/1962","value_type":"String"}]}}

Response: We get the user detail and meta fields to that particular user is added.

All this is fine for us now when we are trying to call the exact same service from our private app while user is registering we are getting below error.

{"errors":"[API] Invalid API key or access token (unrecognized login or wrong password)"}

Can you please help us what we are doing wrong here and if we need to pass anything in the header as we are not passing anything in header from the postman.

vix
Shopify Staff
540 103 121

These are two different APIs. The Buy SDK uses the storefront API and the call you displayed is the admin api

To learn more visit the Shopify Help Center or the Community Blog.

ChuckBlake
Tourist
6 0 0

@vix Yes we are trying to use the Admin API to add meta fields to customer details from our app. If you need we can share the logs from our apps.

vix
Shopify Staff
540 103 121

Okay understood. The first post specifically calls out the SDK which is why I had mentioned that was not possible

We got an issues querying and mutating the data for metafields via iOS and Android Buy SDK.

As the error states, it sounds like you simply do not have your auth correct. Can you confirm how you've setup authentication and re-check the API key + password is being used vs. the storefront access token (storefront API) 

To learn more visit the Shopify Help Center or the Community Blog.

ChuckBlake
Tourist
6 0 0

@vix At the moment we are not doing any Authentication for Admin API as we assume that passing API key + password in the url itself will do the authentication. Also Yesterday we were able to do this from our iOS app but we are still facing issues with Android app