-1

I am new to snipcart and I can’t connect to your APi, i work with Next.js and can’t find anything on the forum or the docs releated to my problem. When I make my call with getServerSideProps i get this unhandledRejectionRequest failed with status code 404. It’s seems that’s I am not authorized to connect however i put my secret API key like in the docs. here my code:

const secret = Buffer.from(process.env.SNIPCART_API_ID).toString('base64');
    const url = 'https://api.snipcart.com/api/products';
    const config = {
        headers: {
            'Content-Type': 'application/json',
            Authorization: `Basic${secret}`,
        },
    };
    axios.get(url, config).then((result) => {
        console.log(result);
    }); ```


Help is welcome :grinning:
Thanks.
Exalus
  • 1
  • 1

1 Answers1

0

From the API Docs:

const secret = "YOUR_SECRET_API_KEY"

const request = await fetch('https://app.snipcart.com/api/orders', {
    headers: {
        'Authorization': `Basic ${btoa(secret)}`,
        'Accept': 'application/json'
    }
})

const result = await request.json()

So what I see are two things:

  1. header NOT "content-type" but "Accept"
  2. Missing space in Authorization Header. Not sure if this is relevant for template strings.
casimirth
  • 11
  • 2
  • Thanks! i was on this since hours and didn't see it was some typo's and wrong read of the docs... – Exalus Jan 22 '22 at 07:32