0

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 got a token using https://login.microsoftonline.com/x/oauth2/token

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"

Can someone give me some advice to what could be the problem? Thanks.

BernardO
  • 1
  • 1

1 Answers1

0

in your POST request to https://login.microsoftonline.com/x/oauth2/token you should use a 'resource' => 'https://api.partner.microsoft.com'.

This PHP code works for me:

public static function getTokenFromCode($code){
    $data = array(
        'resource' => 'https://api.partner.microsoft.com',
        'client_id' => $appId,
        'code' => $code,
        'redirect_uri' => $redirectURL,
        'grant_type' => 'authorization_code',
        'client_secret' => $appKey
    );
    $header = array(
        'Accept: application/json',
        'return-client-request-id: true',
        'Expect: 100-continue'
    );
    $token = self::callApi("POST", 'https://login.microsoftonline.com/'.$accountId."/oauth2/token", $header, $data);

    return $token;
}

public static function getNcePriceList($timeline = "current"){
    $header = array(
        'Authorization: Bearer '.$token['access_token'],
        'Host: api.partner.microsoft.com',
    );
    return self::callApi("GET", "https://api.partner.microsoft.com/v1.0/sales/pricesheets(Market='DE',PricesheetView='updatedlicensebased')/\$value?timeline=".$timeline, $header);
}
  • Hi Ivan Thanks for your answer. But what did you define in your $code? How is this code formed to get a valid token? – BernardO Mar 02 '23 at 14:49
  • Hi, you need to configure a redirect URL for your application on Azure Active Directory (portal.azure.com). After that you can authenticate with this Link: https: //login.microsoftonline.com/your-account-id/oauth2/v2.0/authorize?client_id=your-app-id&response_type=code&redirect_uri=your-redirect-url&response_mode=form_post&scope=offline_access%20openid%20profile%20User.Read%20all_scopes_you_need&state=1 After that you receive a code in a post request. – Ivan Schulz Mar 06 '23 at 13:06