UnAuthorize then asking to Commerce serviceAPI



I have strange behavior...

I am getting the token with httpClient, and all looks fine. I mean I am getting the access token.

When I use the token, for getting all nodes (HTTPS://www.testserver.se/episerverapi/commerce/catalog/{catalogname}/nodes) I am getting unauthorized from serviceAPI. I can only get the token from ServiceAPI when using httpClient.

I added this to my StartUp


The strange thing is when I am using Postman with the same credentials that I am using in httpClient, first get the token, and then use it for getting the nodes (in this case), works fine, but not when I am using in code.

The URL looks good, is the same as in Postman

I have also added the user in Access to Function in Admin, otherwise, it wouldn't work in Postman.

ServiceAPI version: 5.6.1

ServiceAPI Commerce version: 5.6.1

EPiServer: 11.28

EPiServer Commerce: 13.23

Still using .net 4.7

Edited, Nov 17, 2022 22:32

I think you have to add the bearer like this

    client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
Nov 18, 2022 7:36

Hi Quan
Still the same problem...

Nov 18, 2022 11:15

Did you check the request headers? How does it look like?

Nov 18, 2022 12:03

Yes, its in place...

Nov 18, 2022 12:34

Please make sure you have the last backslash after nodes/

I'm guessing here but worth a quick try ?

Nov 18, 2022 13:18

Sounds like Postman is redirecting automatically to a new address, that's why it works, but when using httpclient.

Any idea?...
I also tried to add a "/" at the end, but the same problem.

Nov 18, 2022 13:41

ok so httpclient will loose headers when it gets redirected. You need to make sure you request the dev. url directly 

Nov 18, 2022 14:06

Yes, I am trying to figure it out what the URL is...

Nov 18, 2022 15:20

isn't it dev.something.com:443?

Nov 18, 2022 15:44

I added the rigth url and it works, I also noticed that is case sensitive.

Nov 28, 2022 16:03
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.