Hey there,
when I try the below code to make a basic query for the Shops name and description, I always just get a 401 response.
In the shopify admin under the Apps and sales channel page, I went to App development, created a custom app, gave it scope and then copied the API key from the API Credentials.
I tested the Admin API access token using curl to get [https://{my](https://{my) store}.myshopify.com/admin/api/2024-04/products.json which worked.
But if I try to use the API Key from lower on that page in the mobile app, all I ever get are 401 errors.
On the page https://shopify.dev/docs/custom-storefronts/mobile-apps/buy-sdk-ios (iOS Buy SDK), it does say:
After you've generated an access token,
does that mean we should put the Admin API Access token into the mobile App? Because anyone could extract it from their phone and read it from the app bundle, so the only thing I can imagine is this semi-public API key in the bottom of Custom App - API credentials page.
What also stumps me is that on the github README, the example code uses an apiKey of `
apiKey: "dGhpcyBpcyBhIHByaXZhdGUgYXBpIGtleQ",
which is not a hex string, while the API key on the page https://admin.shopify.com/store/{store}/settings/apps/development/{app id}/api_credentials
is clearly a 32-character hex string/
Here’s the code I used for testing:
client = Graph.Client(
shopDomain: {storename}.myshopify.com,
apiKey: apiKey
)
let query = Storefront.buildQuery { $0
.shop { $0
.name()
.description()
}
}
let task = client.queryGraphWith(query) { response, error in
if let response = response {
log.debug("Response: \(response)")
let name = response.shop.name
} else {
log.error("Query failed: \(String(describing: error))")
}
}
task.resume()