FROM CACHE - en_header

Create API calls in Airtable to get Shopify data

Solved
Dive
Shopify Partner
23 1 1

Hey all !

I'm currently using Airtable to do analytics stuff in my test shop.

In airtable (script app), i can't use the classic way of connecting my store (because my crendentials are exposed) https://{api_key}:{pwa}@{shop_name}/blablabla...
So i tried using the basic auth but i got this error message : "[API] Invalid API key or access token (unrecognized login or wrong password)"

Here is my code :

 

const apiKeyShopify = "MY_API_KEY";
const passwordShopify = "MY_API_PASSWORD";
const nameShopifyStore = "test-dive-analytics.myshopify.com";
const versionApi = '2021-01'
const shopifyUrl = "https://"+nameShopifyStore+"/admin/api/"+versionApi+"/shop.json";
const encodedCredentialsShopify = btoa( apiKeyShopify + ":" + passwordShopify);

const shopifyUrlFull = "https://"+apiKeyShopify+":"+passwordShopify+"@"+nameShopifyStore+"/admin/api/"+versionApi+"/shop.json";

const httpHeader = {
    /*"Access-Control-Allow-Headers" : "Content-Type",
    "Access-Control-Allow-Methods": "GET",*/
    'Content-Type': 'application/json',
    "Authorization": "Basic " + encodedCredentialsShopify
  };

const response = await remoteFetchAsync(shopifyUrl, { 
  method: "GET",
  header: httpHeader
});
await response.json().then(function(res) {
  console.log(res);
});

 

 

Do you know how i can do this ? I'm really struggling and i don't know where is my mistake.

PS: I don't want to use Storefront API.

Thanks a lot for your help !

Thomas.

E-commerce analytics should be easier, that is why we have created diveanalytics.co
Accepted Solution (1)

Accepted Solutions
Dive
Shopify Partner
23 1 1

This is an accepted solution.

Hello @Greg_Kujawa 

 

Thanks for your answer ! Currently i just know how to fix this. (Someone from Airtable community give me his code, all credit to him)

My fetch options was not properly setup ->

let options   = {
    "method": "GET",
    "headers": {
        "Content-Type"  : "application/json",
        "Authorization" : "Basic " + authKey,
    }
}

await remoteFetchAsync(url, options)
    .then((resp) => resp.json())
    .then(function(data) {
        output.inspect(data);
    })
    .catch(function(e) {
        output.markdown("ERROR!");
        output.markdown(e.message);
    });

It fix my issue !

 

Thanks for your time,

Thomas.

E-commerce analytics should be easier, that is why we have created diveanalytics.co

View solution in original post

Replies 2 (2)
Greg_Kujawa
Shopify Partner
1024 84 272

Have you traced the API request to see that the header value is set when being sent over the wire? 

Dive
Shopify Partner
23 1 1

This is an accepted solution.

Hello @Greg_Kujawa 

 

Thanks for your answer ! Currently i just know how to fix this. (Someone from Airtable community give me his code, all credit to him)

My fetch options was not properly setup ->

let options   = {
    "method": "GET",
    "headers": {
        "Content-Type"  : "application/json",
        "Authorization" : "Basic " + authKey,
    }
}

await remoteFetchAsync(url, options)
    .then((resp) => resp.json())
    .then(function(data) {
        output.inspect(data);
    })
    .catch(function(e) {
        output.markdown("ERROR!");
        output.markdown(e.message);
    });

It fix my issue !

 

Thanks for your time,

Thomas.

E-commerce analytics should be easier, that is why we have created diveanalytics.co