Can you pass somehow Shopify API Key and Password through fetch to get data from Shopify API orders,

sstefanm
Tourist
8 2 1

I have a problem with my javascript fetch when I try to run it on the live Shopify store I get this error "{"errors":"[API] Invalid API key or access token (unrecognized login or wrong password)"}" can I somehow pass API key and Password through fetch and get data back from Shopify API REST orders, products, etc.. here is how code looks now.

 

fetch(apiRequest, {
        mode: 'no-cors',
        cache: 'no-cache',
        withCredentials: true,
        credentials: 'same-origin',
        crossdomain: true,
        redirect: 'follow', 
        agent: null, 
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Content-Type': 'application/json',
            'Authorization': 'Basic ' + btoa(`${apiKey}:${password}`)
        }
    })
        .then(response => response.json())
        .then((orders) => {
            orders['orders'].forEach((order) => {
                // console.log(`Orders: `, order);
                // We get all order details and now from then we push to arrays finded product id and variant id it must be the same arrays length //
                order['line_items'].forEach((line) => {
                    productsIds.push(line['product_id']);
                    variantsIds.push(line['variant_id']);
                });
            });
            // Clearning null, duplicates and empty values //
            let products = productsIds.filter((a) => a);
            let variants = variantsIds.filter((a) => a);

            products = [...new Set(products)];
            variants = [...new Set(variants)];

            console.log(`Products ids: `, products);
            console.log(`Variants ids: `, variants);
        })
        .catch((error) => {
            console.log(error);
            alert(error);
        });
Stefan Momcilovic
Replies 0 (0)