I’m trying to retrieve the shop’s metafields and I can do so with Postman and through the URL for basic authorization:
https://{username}:{password}@{shop}.myshopify.com/admin/api/{api-version}/{resource}.json
However when I try to make the call from the server I’m constantly getting 400 errors or a message
{"errors":"[API] Invalid API key or access token (unrecognized login or wrong password)"}
I’ve tried using my public API key and secret key, my private API key and secret, swapping the two url’s I have in the code, hard coding the same access token from the Postman request and I keep getting the invalid API key or access token error. This is a public app that I’d like to use on multiple client stores so I don’t think the private API information is the way to go and using the public API information in the browser works just fine but when I attempt to curl through basic authorization or create the request server side it fails.
My code:
// pages/add-product.js
componentDidMount(){
axios.get('/productMetafields')
.then(res => {
console.log(res);
})
.catch(err => {
console.log(err);
});
}
//server.js
router.get('/productMetafields', verifyRequest(), async (ctx) => {
const { shop, accessToken } = ctx.session;
const url = 'https://'+shop+'/admin/metafields.json';
//const url = 'https://'+SHOPIFY_API_KEY+':'+SHOPIFY_API_SECRET_KEY+'@'+shop+'/admin/metafields.json';
var options = {
"method": "GET",
"headers": {
"Content-Type": "application/json",
"X-Shopify-Access-Token": SHOPIFY_API_SECRET_KEY,
}
};
var req = http.request(url, options, function (res) {
var chunks = [];
res.on("data", function (chunk) {
chunks.push(chunk);
});
res.on("end", function () {
var body = Buffer.concat(chunks);
console.log(body.toString());
});
});
req.end();
});
Your guidance would be much appreciate, auth is constantly tripping me up on this app.