What does "Bad gRPC response. HTTP status code: 401" mean as response in Microsoft Graph?

lignumai 5 Reputation points
2023-05-01T13:59:23.4366667+00:00

I try to use the Microsoft Graph API to access appointments in Microsoft Bookings because I want to be able to automatically delete appointments. I have an access token, I got it using msal for Python. This way worked also to access the IMAP mailbox of my organization. I also got the right permission: https://learn.microsoft.com/en-us/graph/api/bookingbusiness-list-appointments?view=graph-rest-1.0 says I need BookingsAppointment.ReadWrite.All and I have that one, see image. https://i.stack.imgur.com/X8SN1.png

When running the following code:

load_dotenv()
def get_access_token():
    tenant_id = os.getenv("TENANT_ID")
    authority = f'https://login.microsoftonline.com/{tenant_id}'
    clientID = os.getenv("CLIENT_ID_DELETE_BOOKINGS")
    clientSecret = os.getenv("CLIENT_SECRET_DELETE_BOOKINGS")
    scope = 'https://graph.microsoft.com/.default'
    app = msal.ConfidentialClientApplication(clientID, authority=authority, 
          client_credential = clientSecret)
    access_token = app.acquire_token_for_client(scopes=scope)
    return access_token
access_token = get_access_token()
headers = {
    "Authorization": f"Bearer {access_token}"
    # "Content-type": "application/json"
    # "Host": "graph.microsoftonline.com"
}
id_user = #redacted - here is the id in the form of '******@company.nl'
url = f"https://graph.microsoft.com/v1.0/solutions/bookingBusinesses/{id_user}/appointments"
response = requests.request("GET", url=url, headers=headers)
print(response.text)

I get the following response:

{"error":{"code":"UnknownError","message":"{\"error\":{\"message\":\"Bad gRPC response. HTTP status code: 401\",\"code\":\"Unauthorized\"}}","innerError":{"date":"2023-04-28T10:48:01","request-id":"ab1a2ce6-e8ce-4ad1-8950-02d4183a0fab","client-request-id":"ab1a2ce6-e8ce-4ad1-8950-02d4183a0fab"}}}

Especially the Bad gRPC response is something that I cannot find anywhere on the internet except for some .NET fora.

I checked and dubble checked the credentials from my app in Azure, I tried different headers such as "Host": "graph.microsoftonline.com". I expect a normal result as decribed in the Graph documentation, but I keep getting the bad gRPC response. What does this mean and how can I fix it?

Microsoft Security Microsoft Graph
{count} vote

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 46,371 Reputation points
    2023-05-02T10:04:21.66+00:00

    Hi @lignumai

    Do not provide Host in the request header, because your API URL already contains Host. Try changing your script to:

    headers = {
        "Authorization": f"Bearer {access_token}"
    }
    url = f"https://graph.microsoft.com/v1.0/solutions/bookingBusinesses/{business id}/appointments"
    response = requests.request("GET", url=url, headers=headers)
    print(response.text)
    

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.