microsoft / Partner-Center-PowerShell

PowerShell module for managing Partner Center resources.
https://docs.microsoft.com/powershell/partnercenter/
MIT License
130 stars 59 forks source link

Price sheets partner center issue: 401, Unauthorized: Invalid Authorization header #405

Open 0nBernard opened 1 year ago

0nBernard commented 1 year ago

Hi

I am attempting to do an API call to the following: https://learn.microsoft.com/en-us/partner-center/develop/get-a-price-sheet To get a price sheet for a given market and view. But i can not make it work.

I'm able to generate a refresh & access token via powershell, but when I try to call the following API: https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market='be',PricesheetView='updatedlicensebased')/$value

I get a 401, Unauthorized: Invalid Authorization header

My role is Admin Agent on the environment

Can someone help me out?

EdNawrocki commented 1 year ago

I am running into the same problem, did you ever find a solution? This issue has been puzzling me. Other calls to the API which require App + User auth go through just fine, but when I try to get a price sheet or offer matrix I get a 401 unauthorized error. I am also Admin Agent on the envrionment.

rarigita commented 1 year ago

Hi...

Did you solve the issue? I have same situation here... I can access all other API calls of the api.partnercenter.microsoft.com with my access_token/refresh_token but get a 401 Unauthorized when calling the pricesheets API. Also I'm Admin Agent.

Thanks.

EdNawrocki commented 1 year ago

No luck yet. I will continue looking into this and report back if I have any success.

rarigita commented 1 year ago

Hi, I made some advance: Using the refresh_token generated with the authorization_code we request a new access_token. Inspecting the access_token on jwt.io we found its "aud":"https://api.partnercenter.microsoft.com", and with that token we get the 401 response from the pricesheets APIs. We thought it was the issue. So we made a test and added "&resource=https://api.partner.microsoft.com" to the next access_token request from refresh_token, and inspecting the token we see "aud":"https://api.partner.microsoft.com". So now we used this new token in the Authorization header of the pricesheet API and it worked, but only with one of the two files we want to dowload:

Response 200 OK: https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market='ES',PricesheetView='updatedlicensebased')/$value -> Receive the CSV data correcty

400 Malformed: https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market='ALL',PricesheetView='legacy_license_based')/$value

Now we don't get a 401 on both requests, but the legacy_license_based gives a 400 Error and a message of Wrong Pricesheet or malformed Headers.

Its weird as I inspected the same requests from the https://partner.microsoft.com/dashboard while click on pricesheet download, and inspecting the Bearer token it looks very similar to the one I generate from my refresh_token. If I copy the web token, it works with my curl CLI request and I get the legacy_license_based without issues, but that Bearer token is generated by the partner web appId, not with our appId and our refresh_token.

Do you understand? Now my issue is how to get the legacy_license_based pricesheet, as I don't know where to look for this.

Danishminhas12 commented 7 months ago

rarigita I Follow your Instruction and I resolve my Issue Thanks.

abrantie11z commented 7 months ago

@Danishminhas12 can you show me how you got your working? I happen to be using the sample Partner Consent and CSPApplication recommended on here : https://learn.microsoft.com/en-us/partner-center/developer/partner-center-authentication. I also tried to add "&resource=https://api.partner.microsoft.com/" to the request that retrieves the access token, but that return s null.

Danishminhas12 commented 7 months ago

Sure we do a meeting will guide you.

On Fri, 26 Jan 2024, 22:29 Godfred, @.***> wrote:

@Danishminhas12 https://github.com/Danishminhas12 can you show me how you got your working? I happen to be using the sample Partner Consent and CSPApplication recommended on here : https://learn.microsoft.com/en-us/partner-center/developer/partner-center-authentication . I also tried to add "&resource=https://api.partner.microsoft.com/" to the request that retrieves the access token, but that return s null.

— Reply to this email directly, view it on GitHub https://github.com/microsoft/Partner-Center-PowerShell/issues/405#issuecomment-1912422318, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFPO62CMBCELMRZ2PCIGA6DYQPRYFAVCNFSM6AAAAAAT7GUTRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJSGQZDEMZRHA . You are receiving this because you were mentioned.Message ID: @.***>

Danishminhas12 commented 7 months ago

@abrantie11z contact with me through email i will share screen and show you how i access.

abrantie11z commented 7 months ago

Thank You @Danishminhas12 . Can you please share your email here?

Danishminhas12 commented 7 months ago

@abrantie11z Danishminhas756@gmail.com

abrantie11z commented 7 months ago

@Danishminhas12 I did not hear from you again..

Danishminhas12 commented 7 months ago

Hey sorry i am busy in one project today i will contact with you sure.

On Tue, 30 Jan 2024 at 15:04, Godfred @.***> wrote:

@Danishminhas12 https://github.com/Danishminhas12 I did not hear from you again..

— Reply to this email directly, view it on GitHub https://github.com/microsoft/Partner-Center-PowerShell/issues/405#issuecomment-1916486366, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFPO62GAR7BDREUWKHNRTKTYRDAUHAVCNFSM6AAAAAAT7GUTRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJWGQ4DMMZWGY . You are receiving this because you were mentioned.Message ID: @.***>

Danishminhas12 commented 7 months ago

Sorry for that.

On Tue, 30 Jan 2024 at 15:05, d mehmood @.***> wrote:

Hey sorry i am busy in one project today i will contact with you sure.

On Tue, 30 Jan 2024 at 15:04, Godfred @.***> wrote:

@Danishminhas12 https://github.com/Danishminhas12 I did not hear from you again..

— Reply to this email directly, view it on GitHub https://github.com/microsoft/Partner-Center-PowerShell/issues/405#issuecomment-1916486366, or unsubscribe https://github.com/notifications/unsubscribe-auth/BFPO62GAR7BDREUWKHNRTKTYRDAUHAVCNFSM6AAAAAAT7GUTRKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJWGQ4DMMZWGY . You are receiving this because you were mentioned.Message ID: @.***>

abrantie11z commented 7 months ago

Ok, hanging on

GH-KimV commented 7 months ago

Hi, I made some advance: Using the refresh_token generated with the authorization_code we request a new access_token. Inspecting the access_token on jwt.io we found its "aud":"https://api.partnercenter.microsoft.com", and with that token we get the 401 response from the pricesheets APIs. We thought it was the issue. So we made a test and added "&resource=https://api.partner.microsoft.com" to the next access_token request from refresh_token, and inspecting the token we see "aud":"https://api.partner.microsoft.com". So now we used this new token in the Authorization header of the pricesheet API and it worked, but only with one of the two files we want to dowload:

Response 200 OK: https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market='ES',PricesheetView='updatedlicensebased')/$value -> Receive the CSV data correcty

400 Malformed: https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market='ALL',PricesheetView='legacy_license_based')/$value

Now we don't get a 401 on both requests, but the legacy_license_based gives a 400 Error and a message of Wrong Pricesheet or malformed Headers.

Its weird as I inspected the same requests from the https://partner.microsoft.com/dashboard while click on pricesheet download, and inspecting the Bearer token it looks very similar to the one I generate from my refresh_token. If I copy the web token, it works with my curl CLI request and I get the legacy_license_based without issues, but that Bearer token is generated by the partner web appId, not with our appId and our refresh_token.

Do you understand? Now my issue is how to get the legacy_license_based pricesheet, as I don't know where to look for this.

Thank you! This was driving me nuts @rarigita Now I'm also stuck on legacy licenses. Ive spent most of my days in the web console to see if there's anything I can grab

mprentice22153 commented 7 months ago

@rarigita I see you have the Market='ALL' in your second query. Have you tried Market='ES'?