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. Permissions screenshot.
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 'appointmenttype@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.