合作伙伴中心休息API 401错误 [英] Partner Center rest api 401 error

查看:121
本文介绍了合作伙伴中心休息API 401错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用partnercenter api来获取帐单详细信息.但是API调用返回401错误代码.如果我将它作为Subscription API的输入,在partnercpi上提供的详细信息是正确的并且可以正常工作.

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.

参考链接: https://msftstack.wordpress.com/2016/01/05/azure-resource-manager-authentication-with-python/

这是我的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

输出响应:

<Response [401]>

此方法不适用于partnerapi用法集合吗?如果不是,请建议替代方案.预先感谢.

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

推荐答案

401是因为合作伙伴中心不能仅使用Azure AD中的令牌.

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

实际的Auth工作流程

The actual Auth workflow

  1. 从Azure AD获取令牌.
  2. 使用该令牌从PartnerCenter获取访问令牌.
  3. 使用此令牌与合作伙伴中心REST API通信.

更多信息此处

这篇关于合作伙伴中心休息API 401错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆