Problems connecting to Snipcart REST Api

Problems connecting to Snipcart REST Api

  

Hi,


I'm trying to connect to the Snipcart REST Api, but I keep getting the error I'm 'not authorized'. I'm pretty sure I am, so I think I'm not connecting correctly.


This is the call I should be making according to the website of snipcart:

curl -H "Accept: application/json" \
  https://app.snipcart.com/api/orders \
  -u {API_KEY}:

(More info on https://docs.snipcart.com/api-reference/authentication)

I have tried this using the predefined headers in Outsystems Accept and Authorization. Did not work. Tried it with predefined Accept and https://app.snipcart.com/api/orders \u {API_KEY} but that didn't work either. Tried several other variants less likely to succeed and they didn't.


Can anybody help me with the correct call/translation in Outsystems to connect to Snipcart?


Thanks in advance,


Rikki

Hi Rikki,

As the API documentation you linked to says, Snipcart uses basic authentication. If you have a "secret key", as they call it, without a seperate username and password, you need to add a header "Authorization", with value "Basic " + your key. The easiest way to do it in OutSystems, is to add an Authorization input parameter to the Method you're trying to consume, and set its value to "Basic " + your key (probably you want a site property to store it, so it would be something like "Basic " + Site.ApiKey):

However, if you have many Methods that all use the same authentication this is laborious and error prone. In that case, it's better to add an OnBeforeRequest to the REST API, and add the authentication header in there.

Hi Rikki,

I overlooked something when giving the reply above. It seems the Snipcart secret key is actually treated as the username of the basic auth, and the password is empty. This means that you can simply set the username in the "Username" Property of the API (without all the other things I mentioned above):

Hi Killian,


Thanks for quick reply again. Unfortunately it's still not working at my end. I have tried several things, filling in at the Username-field "Basic" (also "basic") and still use Authorization in the REST-service, put my API key in the Username-field with password empty, etc, etc. See screenshots below for one of the things I tried, with password as my api_key.


My API_KEY is ST_ZjRiMjA1MTgtNDg4My00YmVkLThiN2EtY2UwMGYzYjBkN2VlNjM2Njc2OTkxNzc1NTE4MDI3

Feel free to use this, I will change it once we are successful in logging in.


Thanks again for your efforts, hope we can get this up and running soon.


Rikki



Kilian Hekhuis wrote:

Hi Rikki,

I overlooked something when giving the reply above. It seems the Snipcart secret key is actually treated as the username of the basic auth, and the password is empty. This means that you can simply set the username in the "Username" Property of the API (without all the other things I mentioned above):




Solution

Hi Rikki,

It works without problem here. I'm not sure why you entered "basic" as username, and filled in a password, while I told you to user the key as username and leave the password empty?

P.S. You might wanna change the API Key right now, as it seems you've added your home address somewhere? At least I see a Rotterdam address...

Solution

Hi Killian,


Works now for me as well. Changed the API-key.

The reason why I filled in 'basic' and the api_key as the password is that it was not working and I didn't stop trying different solutions. :-)


It only works at my end if I fill in the api_key in Username but also fill in something in the password field as well. Otherwise the Basic Authentication values don't show up in the REST-service. I have to fill in at least a space in Password for them to show up. Does not matter the value used in the password-field, it is obviously ignored by Snipcart. But that is the only way for me to make it work.Otherwise I get the 'not authorized' response.


Thanks for your help, you have made it possible for me to continue to use this solution for my shop!


Rikki


Kilian Hekhuis wrote:

Hi Rikki,

It works without problem here. I'm not sure why you entered "basic" as username, and filled in a password, while I told you to user the key as username and leave the password empty?

P.S. You might wanna change the API Key right now, as it seems you've added your home address somewhere? At least I see a Rotterdam address...



Mmm, weird, I didn't need to fill anything for the password. Anyway, great you got working now!