API to get a price sheet from partner center

649 Views Asked by At

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.

1

There are 1 best solutions below

2
Ivan Schulz On

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);
}