Struggling to return successful API requests with Next.js

Hello there,

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 tthat’s i’m notI 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.

Hi @exalus

Make sure that there is a space between Basic and ${secret}, add : to the end of the API key, and check your URL. Our API is at *app*.snipcart.com/api and not *api*.snipcart.com/api.

Let me know if that helps.

Thanks.

Hello @nelitow , thanks for your fast reply.

So now it works, as you mention my errors was in the URL and the missing space also i was using the public API key… :roll_eyes:
Sorry about my stupid question :sweat_smile:

Thanks for your help and for your time.
Axel.

No worries, we’re here to help :slight_smile:

1 Like