Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Trying to automate pulling the licensebased prices every month #414

Open
freddy-lopez-dev opened this issue Sep 13, 2023 · 2 comments
Open

Comments

@freddy-lopez-dev
Copy link

I was trying to setup an azure Powershell automation with New-PartnerAccessToken trying to invoke-restmethod for pulling up the prices. The access token received from the cmdlet doesn't seem to work and it always gives me a 401 Unauthorized error.

Steps to reproduce

This is my command:
$appId = 'xxxxxxxxxxxx'
$appSecret = 'xxxxxxxxxxx' | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $appId, $appSecret
$token = New-PartnerAccessToken -Credential $credential -Resource https://api.partnercenter.microsoft.com -ServicePrincipal
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Accept", "application/json")
$headers.Add("Authorization", "Bearer $token")
$response = Invoke-RestMethod 'https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market=''ca'',PricesheetView=''updatedlicensebased'')/$value' -Method 'GET' -Headers $headers

Expected behavior

I should receive the CSV format of product prices

Actual behavior

401 Unauthorized

Environment

Sandbox
5.1

@moiaune
Copy link

moiaune commented Jan 12, 2024

I think that you are setting your Authorization header the wrong way, because the $token variable will be an object containing multiple fields.

Try this instead:

$headers.Add("Authorization", "Bearer $($token.AccessToken)")

You can also take a look at this blog post on how I do it which is a bit different: https://moiaune.dev/2021/11/03/generate-microsoft-partner-center-refresh-token/

@GH-KimV
Copy link

GH-KimV commented Feb 9, 2024

I was trying to setup an azure Powershell automation with New-PartnerAccessToken trying to invoke-restmethod for pulling up the prices. The access token received from the cmdlet doesn't seem to work and it always gives me a 401 Unauthorized error.

Steps to reproduce

This is my command: $appId = 'xxxxxxxxxxxx' $appSecret = 'xxxxxxxxxxx' | ConvertTo-SecureString -AsPlainText -Force $credential = New-Object System.Management.Automation.PSCredential $appId, $appSecret $token = New-PartnerAccessToken -Credential $credential -Resource https://api.partnercenter.microsoft.com -ServicePrincipal $headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" $headers.Add("Accept", "application/json") $headers.Add("Authorization", "Bearer $token") $response = Invoke-RestMethod 'https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market=''ca'',PricesheetView=''updatedlicensebased'')/$value' -Method 'GET' -Headers $headers

Expected behavior

I should receive the CSV format of product prices

Actual behavior

401 Unauthorized

Environment

Sandbox
5.1

you need to add resource and have the value be api.partner.microsoft.com in the body data in your request

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants