Partner Center rest api 401 error

杀马特。学长 韩版系。学妹 提交于 2019-12-11 08:08:00

问题


I tried to use partnercenter api to get the billing details. But API call return 401 error code. the details provided on partnercpi are correct one and its working fine If I give it as input for Subscription API.

URL : https://api.partnercenter.microsoft.com/v1/customers/<Customer-tenant-ID>/subscriptions/<Subscription-ID>/usagerecords/resources

Can you suggest what can be the reason for the error.

Reference link : https://msftstack.wordpress.com/2016/01/05/azure-resource-manager-authentication-with-python/

Here is my python code.

import adal
import requests


application_secret = 'asdq23Y+tRgEspFxQDPasd'
application_id = '523129-1267b-123'


authentication_endpoint = 'https://login.microsoftonline.com/'
resource  = 'https://management.core.windows.net/'

context = adal.AuthenticationContext(authentication_endpoint + tenant_id)
token_response = context.acquire_token_with_client_credentials(resource, application_id, application_secret)

access_token = token_response.get('accessToken')


endpoint = "https://api.partnercenter.microsoft.com/v1/customers/<customer tenant ID>/subscriptions/<sub-id>/usagerecords/resources"


headers = {"Authorization": 'Bearer ' + access_token}

json_output = requests.get(endpoint,headers=headers)
print json_output

Output Response:

<Response [401]>

Is this method not fit for partnerapi usage collection ?. If not pls suggest alternate option. Thanks in advance.


回答1:


401 is because partner center does not work with just the token from Azure AD.

The actual Auth workflow

  1. Get a Token from Azure AD.
  2. Use that token to get an access token from PartnerCenter.
  3. Use this token to communicate with the partner center REST APIs.

More Info Here



来源:https://stackoverflow.com/questions/43134131/partner-center-rest-api-401-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!