Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

UnAuthorize then asking to Commerce serviceAPI

Vote:
 

Hi

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

app.UseServiceApiMembershipTokenAuthorization();

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

#291844
Edited, Nov 17, 2022 22:32
Vote:
 

I think you have to add the bearer like this

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

Hi Quan
Still the same problem...

#291889
Nov 18, 2022 11:15
Vote:
 

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

#291891
Nov 18, 2022 12:03
Vote:
 

Yes, its in place...

#291893
Nov 18, 2022 12:34
Vote:
 

Please make sure you have the last backslash after nodes/

I'm guessing here but worth a quick try ?

#291894
Nov 18, 2022 13:18
Vote:
 

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.

#291897
Nov 18, 2022 13:41
Vote:
 

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

#291898
Nov 18, 2022 14:06
Vote:
 

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

#291900
Nov 18, 2022 15:20
Vote:
 

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

#291902
Nov 18, 2022 15:44
Vote:
 

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

#292342
Nov 28, 2022 16:03
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.