Outlook Web hook Subscription - python-3.x

I am working with Outlook Webhook Subscriptions and working on QA server.
According to the Microsoft Graph documentation, we need to send the request to get the webhook notification. I am using Python 3 request module for this.
I am sending the following data but getting the error. I can't figure out where I am going wrong in the process.
url="https://graph.microsoft.com/v1.0/subscriptions"
header={
'Content-Type': 'application/json',
'Authorization':"Bearer "+ "valid access token"
}
data={
"changeType": "created,updated",
"notificationUrl": "https://qa.example.com/get_webhook",
"resource": "/me/mailfolders('inbox')/messages",
"expirationDateTime": "2018-12-11T11:00:00.0000000Z"
}
response=requests.post(url, headers=header, data=data)
After executing the above lines I am getting the following <400> response
'{\r\n "error": {\r\n "code": "BadRequest",\r\n "message":
"Unable to read JSON request payload. Please ensure Content-Type
header is set and payload is of valid JSON format.",\r\n
"innerError": {\r\n "request-id": "3a15ba2f-a055-4f33-a3f8-
f1f40cdb2d64",\r\n "date": "2018-12-10T06:51:32"\r\n }\r\n
}\r\n}'

To post as JSON, you need to json property rather than the data property (i.e. json={"key": "value"}:
url="https://graph.microsoft.com/v1.0/subscriptions"
header={
'Content-Type': 'application/json',
'Authorization':"Bearer "+ "valid access token"
}
data={
"changeType": "created,updated",
"notificationUrl": "https://qa.example.com/get_webhook",
"resource": "/me/mailfolders('inbox')/messages",
"expirationDateTime": "2018-12-11T11:00:00.0000000Z"
}
response=requests.post(url, headers=header, json=data)

You can use:
import json
response=requests.post(url, headers=header, data=json.dumps(data))

Related

/range option for graph API accessing a excel file on Sharepoint (with table) results in 400 response

Since 01/29/2022 the below get request is resulting in a 400 response
v1.0/sites/{site_id}/drives/{drive_id}/items/{doc_id}/workbook/worksheets/Sheet1/tables/{table_name}/range
whereas
v1.0/sites/{site_id}/drives/{drive_id}/items/{doc_id}/workbook/worksheets/Sheet1/tables/{table_name}
v1.0/sites/{site_id}/drives/{drive_id}/items/{doc_id}/workbook/worksheets/Sheet1/tables/{table_name}/rows
results in a 200 response.
The http headers payloads are accurate (Authorization, content type)
Here is my python Code
Note: the code below (and above) - the sensitive information has been redacted.
import requests
url = 'https://graph.microsoft.com/v1.0/sites/{organization share point site}/drives/{drive-id}/items/{document-id}/workbook/worksheets/Sheet1/tables/{table name}/range'
print (url)
http_headers = {'Authorization': 'Bearer {my key}', 'Accept': 'application/json', 'Content-Type': 'application/json', 'Cache-Control': 'no-cache', 'verify' : 'True'}
x = requests.get(url=url,headers=http_headers,stream=False)
print(x.status_code)
If your table is too large you can receive response status 400 with the following error
{
"error": {
"code": "ResponsePayloadSizeLimitExceeded",
"message": "The size of the payload exceeded the limit. Read the documentation: https://learn.microsoft.com/office/dev/add-ins/concepts/resource-limits-and-performance-optimization#excel-add-ins.",
"innerError": {
"code": "responsePayloadSizeLimitExceeded",
"message": "The size of the payload exceeded the limit. Read the documentation: https://learn.microsoft.com/office/dev/add-ins/concepts/resource-limits-and-performance-optimization#excel-add-ins.",
"date": "2022-02-01T12:38:03",
"request-id": "cae21c5d-8a48-4a22-ad4d-8994de9325ef",
"client-request-id": "7a46b35e-7f15-1d22-75c3-dd867d0d48b5"
}
}
}

Azure Keyvault Sign API - Response body “value” encoding format

When I do a post request to the Azure Key Vault Sign API: https://pkitstencryptkeyvault.vault.azure.net/keys/openssl-rbi-test/1ccc8fc0e0224bb1a65eb159e2b12df1/sign?api-version=7.0
with body:
{
"alg": "ES256",
"value": "RkQ4y5rDgxeaaOzeqeAFT3IGLAEZMz2ztbTbMNzxuMc"
}
The response is:
{
"kid": "https://pkitstencryptkeyvault.vault.azure.net/keys/openssl-rbi-test/1ccc8fc0e0224bb1a65eb159e2b12df1",
"value": "d9J4G06FRMBEKy_FJJj1PEAXhtlezvd6-3_5yo9yeYAFZ_Du583AJzqu3NMTzJAUMoKhnVBx2obnkM0gI1LnoQ"
}
I can't find that information on the Azure Sign API doc.
So what is the format of the value in the response body?
I'm asking this, because when I send a verify request to:
https://pkitstencryptkeyvault.vault.azure.net/keys/openssl-rbi-test/1ccc8fc0e0224bb1a65eb159e2b12df1/verify?api-version=7.0 with body:
{
"alg": "ES256",
"value": "d9J4G06FRMBEKy_FJJj1PEAXhtlezvd6-3_5yo9yeYAFZ_Du583AJzqu3NMTzJAUMoKhnVBx2obnkM0gI1LnoQ"
}
I get the following error:
{
"error": {
"code": "BadParameter",
"message": "Property has invalid value\r\n"
}
}
Although the example does not show it: The digest parameter is missing in your verify request body. This parameter is defined in the API.

How to fix HTTP-Status 401 (Unauthorized) on bot-connector when calling the facebook-messenger webhook?

After setting up a bot-connector (SAP Conversational AI: https://github.com/SAPConversationalAI/bot-connector), creating a channel for the fb-messenger and configuring a webhook in the fb-app i constantly get http-status 401 (unauthorized) in my bot-connector log when sending a message from my fb-messenger.
Here is what i've done so far: (i fallowed this guide: https://github.com/SAPConversationalAI/bot-connector/wiki/Channel---Messenger)
deployed bot-connector to google cloud as app engine service to get the [bot-connector url]
created bot-connector:
POST on [bot-connector url]/v1/connectors with body:
{"url":[bot-connector endpoint url]}
POST-response:
{
"results": {
"id": [connector id],
"url": [bot-connector endpoint url],
"isTyping": true,
"conversations": [],
"channels": []
},
"message": "Connector successfully created"
}
created channel for fb-messenger:
POST on [bot-connector url]/v1/connectors/[connector id]/channels with body:
{
"slug":"channel-messenger-srtbot-dev",
"type":"messenger",
"token":[fb-app secret],
"apiKey":[fb-app api-key],
"isActivated":true
}
POST response:
{
"results": {
"id": [connector id],
"updatedAt": "2019-01-22T15:03:29.569Z",
"createdAt": "2019-01-22T15:03:29.569Z",
"webhook": "/v1/webhook/[channel id]",
"slug": [name of my channel],
"type": "messenger",
"token": [fb-app secret],
"apiKey": [fb-app api-key],
"connector": [connector id],
"locales": [],
"openingType": "never",
"hasGetStarted": false,
"forwardConversationStart": false,
"isActivated": true,
"isErrored": false,
"webhookToken": [fb webhook token]
},
"message": "Channel successfully created"
}
configured fb-messenger-webhook: (after completing the config i get the http-status 200 in the bot-connector log)
callback-url: [bot-connector url]/v1/webhook/[channel id]
token: [fb webhook token]
subscribed webhook to my fb-page
sent a message in my fb-messenger
Expected results:
after i send a message in the fb-messenger:
http-status 200 in the bot-connector log
messages gets forwarded to [bot-connector endpoint url]
bot responds to the message (i get an answer in the fb-messenger)
Actual results:
after i send a messag in the fb-messenger:
http-status 401 (unauthorized) in the bot-connector log (approximately every 60 seconds after the first fb-messenger message)
nothing else happens
i get no answer in the fb-messenger
When creating the channel, the app secret should be passed as the apiKey attribute and the page token as the token attribute. When the channel is created, it will have a webhookToken attribute. This should be used as the verify token when setting up the webhook on Facebook.
So instead what you should be passing to create the channel, should look like this:
{
"slug":"channel-messenger-srtbot-dev",
"type":"messenger",
"token":[fb-page token],
"apiKey":[fb-app secret],
"isActivated":true
}

Azure Logic Apps Cannot send HTTP request for wns/raw notification

I have a small logic app which is meant to fetch data from somewhere and store it on blob. I then would like to send the URL to all devices via push notification. I wish to send the URL as a raw notification, so on the app/background task, i can do some processiong.
The problem is when i use logic app to create a http POST request to send a notification, i get a 400 error. The same header with authentication and etc, with the payload and URL works fine on a POSTMAN or REST API CLIENT. THe following are the inputs and outputs. Please help. Brain dead already.
This is the input.
{
"uri": "https://xxoppoc.servicebus.windows.net/xxopPOC/messages/?api-version=2015-01",
"method": "POST",
"headers": {
"Authorization": "SharedAccessSignature sr=sb%3a%2f%2fxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxt%2f&sig=qEnxxxxxxxxxxxx&skn=DefaultFullSharedAccessSignature",
"Content-Type": "application/octet-stream",
"ServiceBusNotification-Format": "windows",
"ServiceBusNotification-Tags": "MyTag",
"X-WNS-Type": "wns/raw"
},
"body": "Some Raw Information. Hello World"
}
This is the output:
{
"statusCode": 400,
"headers": {
"transfer-Encoding": "chunked",
"date": "Wed, 30 Mar 2016 14:10:41 GMT",
"server": "Microsoft-HTTPAPI/2.0"
},
"body": {
"$content-type": "application/xml; charset=utf-8",
"$content": "PEVycm9yPjxDb2RlPjQwMDwvQ29kZT48RGV0YWlsPlRoZSBjb250ZW50IHR5cGUgZm9yIGEgJ3ducy9yYXcnIG5vdGlmaWNhdGlvbiBtdXN0IGJlICdhcHBsaWNhdGlvbi9vY3RldC1zdHJlYW0nLlRyYWNraW5nSWQ6NTNmNjhlMGItNDc1MC00ZDRkLWJiNTAtMzJjNTBmOGIyNDk1X0czLFRpbWVTdGFtcDozLzMwLzIwMTYgMjoxMDo0MSBQTTwvRGV0YWlsPjwvRXJyb3I+"
}
}
Let me mention again, I got the authentication correct as it works on Advanced REST Client on chrome and POSTMAN. The above logic app also works if i send a wns/toast notification with xml as its content-type. I however need it to be a wns/raw notification. Please help. Thank you
EDIT/PROGRESS
Thanks to MichaelB, We figured out that the content-type is being modified. I sent the request to a different URL to look at the header. The following was observed:
Content-Type: application/octet-stream; charset=utf-8
If I use the above Content-Type on POSTMAN. It actually fails as well. So this could be 1 step. Why is Azure Logic Apps adding charset-utf-8 to the end of my content type. Can I stop it?

creating subscription with Microsoft Graph API error

I'm trying to create a subscription to receive notification about changes to Office365 Calendar. I have already worked with Outlook Notitication API but having a problem with Microsoft Grap API
I try to create a subscription using Http Post to https://graph.microsoft.com/beta/subscriptions with header and body:
Header: Content-Type: application/json; Authorization : Bearer {accessToke}
Body:
{
"resource": "me/calendars",
"notificationUrl": "sample notification url",
"changeType": "Created",
}
In my notification url, i've setup to send a response with the value of validation token when receveving a validation request
Finally, the result i received:
{
"error": {
"code": "ExtensionError",
"message": "There was an error processing a storage extension.",
"innerError": {
"request-id": "6c563931-511d-415d-9c04-c07f25d45b1f",
"date": "2016-03-20T08:10:32"
}
}
}
I wonder what I'm doing wrong or that's a internal error of MS Grap API. Can anyone help me? Thank in advance
The correct resource to use for calendar events is "me/events". We'll try to get a better error message in future.

Resources