Microsoft partner center API to get customer list, not returning any customer List.

Pradeep Kumar 5 Reputation points
2023-08-11T09:22:16.05+00:00

Hi team,

When I am trying to pull the customer list using partner center API, it's returning nothing in the response text, and the response status code is 401 even when my application applicationId, secretKey, and tenantId are valid I have cross-verified it many times and added all required API permissions to the application. I have added my code below.

Token generation:-



client_id = "-------"
client_secret = "---------"
tenant_id = "-----------"
base_url = "https://graph.microsoft.com/v1.0"
partnerserviceurl = "https://api.partnercenter.microsoft.com"
authorityurl = "https://login.microsoftonline.com"
auth_endpoint = authorityurl

headers = {"Accept": "application/json", "x-ms-correlation-id": str(uuid.uuid1()), "x-ms-tracking-id": str(uuid.uuid1())}

data = {"client_id": client_id, "grant_type": "client_credentials",        "resource": "https://graph.windows.net", "client_secret": client_secret}

url = f'{authorityurl}/{tenant_id}/oauth2/token'
try:    
	with httpx.Client() as client:        
		token_resp = client.post(url, data=data, headers=headers)    
		if int(token_resp.status_code / 100) != 2:        
			print(f"Authentication B2c Error {token_resp.text}")    
		else:        
			token_resp = token_resp.json()        
			access_token = token_resp['access_token']
except Exception as err:    
	print(f"Error Get Access Token {err}")
	return False, ""

authorization = "Bearer " + access_token
headers["Authorization"] = authorizationprint(access_token)
return True, access_token


To Pull the Customer List:-

if not url:    
	url = partnerserviceurl + "/v1/customers?size=900"
if not headers:    
	headers = {"Authorization": "Bearer " + access_token, "Accept": "application/json",               "MS-RequestId": str(uuid.uuid1()), "MS-CorrelationId": str(uuid.uuid1())}
resp = requests.get(url, headers=headers, verify=False)
print(resp.text)
print(resp.status_code)

Response:-
<empty string>
401

Any help or suggestion on this will be highly appreciated.

Thanks

Pradeep

Microsoft Partner Center API
Microsoft Partner Center API
Microsoft Partner Center: A Microsoft website for partners that provides access to product support, a partner community, and other partner services.API: A software intermediary that allows two applications to interact with each other.
328 questions
0 comments No comments
{count} vote