I am new to app development. My aim is to use the Shopify API to access orders in our Shopify store.
I have set up a private test app and given it just about every possible permission.
I keep getting a 401 using the script below and I am wondering if there is an automated way to check that the app has been properly configured.
Thx, Eric
const fetch = require(‘node-fetch’);
const shopifyDomain = ‘MyStoreName.myshopify.com’; // Replace with your Shopify domain
const accessToken = ‘MyAdminAccessToken’; // Replace with your admin access token
const testApi = async () => {
const url = https://${shopifyDomain}/admin/api/2023-01/shop.json;
try {
const response = await fetch(url, {
method: ‘GET’,
headers: {
‘Content-Type’: ‘application/json’,
‘X-Shopify-Access-Token’: accessToken
}
});
if (!response.ok) {
throw new Error(Error: ${response.status} - ${response.statusText});
}
const data = await response.json();
return data.shop;
} catch (error) {
console.error(‘Error testing API:’, error.message);
}
};
testApi().then(shop => {
if (shop) {
console.log(‘Successfully connected to the shop:’, shop);
}
});