UnknownError when creating a MicrosoftGraph subscription - microsoft-graph-api

I am working on a project to set up a webhook with Microsft graph. I have everything set up to validate the endpoint I have created as per (https://developer.microsoft.com/en-us/graph/docs/concepts/webhooks), however, I am receiving an "Unknown Error" from Microsoft as follows:
"__SLOG0__", "{
\"error\": {
\"code\": \"UnknownError\",
\"message\": \"\",
\"innerError\": {
\"request-id\": \"d0037849-dc79-4244-bb15-cf72841c6653\",
\"date\": \"2018-10-22T20:00:43\"
}
}
}"
I create the subscription with the following values:
$body_vals = dict[
"changeType" => "created,updated",
"notificationUrl" => $notification_uri,
"resource" => "/me/mailfolders('inbox')/messages",
"expirationDateTime" =>
Office365APIUtils::getISO8601DateStamp($date->getTimestamp()),
"clientState" => "SecretClientState",
]
passed into my POST request to the endpoint. I know this has to do with my specific notification uri (which is a facebook endpoint) because if i switch the endpoint to https://google.com, for example, I get a more helpful response:
"__SLOG0__", "{
\"error\": {
\"code\": \"InvalidRequest\",
\"message\": \"Subscription validation request failed. Must respond with 200 OK to this request.\",
\"innerError\": {
\"request-id\": \"4e2ac4af-4d10-416d-83a1-4eb896a35418\",
\"date\": \"2018-10-22T19:52:46\"
}
}
}"
saying I have to validate at the endpoint. I already registered my app, if there is anyone with the Graph team or that has dealt with this before with any leads on these UnknownErrors? an example request-id is 7da743ce-6ffe-4d80-8611-a5be024c8b21

It looks like your code may not be performing the endpoint validation step. This article contains a complete walk-through of how to create a subscription. Have a look at the "Notification endpoint validation" section; your endpoint must be able to respond with 200 and include the validation token.

Related

microsoft Graph API for subscription throwing wrong message and not creating subscription

I am using Microsoft graph API and trying to create a subscription on the Microsoft developer portal.
https://graph.microsoft.com/v1.0/subscriptions I am hitting this URL with post request call as shown below
`
import requests
access_token = "testtoken"
subscription_data = {
"changeType": "created,updated",
"notificationUrl": "WEBHOOK URL",
"resource": "me/contacts",
"expirationDateTime": '2023-01-16T16:58:00.0000000Z'
}
headers = {
'Authorization': 'Bearer ' + access_token,
'Content-Type': 'application/xml'
}
try:
response = requests.post(f'https://graph.microsoft.com/v1.0/subscriptions', json=subscription_data, headers=headers)
except Exception as e:
print("error")
Above code is giving wrong message response as
`{
"error": {
"code": "InvalidRequest",
"message": "Could not process subscription creation payload. Are all property names spelled and camelCased properly?Also are the dateTimeOffest properties in a valid internet Date and Time format?",
"innerError": {
"date": "2023-01-14T19:09:17",
"request-id": "6d50105e-08b1-494d-8400-5fc32909a8d1",
"client-request-id": "c89e988f-783b-daf5-7d95-677002b0c22d"
}
}
}
`
As you see all property are in camelcase and date format is also in 8601 iso format,
still getting errors and not able to create a subscription . I also saw similar problem faced and discussed here https://github.com/microsoftgraph/microsoft-graph-docs/issues/3041 however this is also not giving explanations how to solve the problem

Create Team, 400 Bad Request, Required functionality is not supported

I'm trying to create a Microsoft Teams team in Migration mode via the Graph API. However I get a 400 response that I can't figure out. The query is shared in the link below.
Shared Query
For those that don't want to view it that way, here is my request:
POST https://graph.microsoft.com/beta/teams
Authorization: Bearer ...
Content-Type: application/json
{
"#microsoft.graph.teamCreationMode": "migration",
"template#odata.bind": "https://graph.microsoft.com/beta/teamsTemplates(\u0027standard\u0027)",
"displayName": "SlackMigrationTest",
"description": "testing slack migrations",
"createdDateTime": "2021-01-14T00:00:00.000Z"
}
I created this based on the microsoft doc here.
The reponse I get is:
The remote server returned an error: (400) Bad Request.
{
"error": {
"code": "BadRequest",
"message": "Required functionality is not supported.",
"innerError": {
"date": "2021-01-20T15:51:21",
"request-id": "dc4189cf-db4a-4a60-a271-f63b5d759a05",
"client-request-id": "dc4189cf-db4a-4a60-a271-f63b5d759a05"
}
}
}
I'm sure its something obvious that I'm missing but any help would be greatly appreciated.
Here you are using the User Context token and trying to make the call. This API call only works in Application context as shown in the below screenshot.
So use Client Credential flow and set Application permissions and then make a call.
As you can see below, it worked for me with App token.
You cannot test it in graph explorer because the Graph Explorer gets user token.

"Subscription validation request failed. Response must exactly match validationToken query parameter."

I have the requirement to enable a subscription for change notifications for OneDrive (me/drive/SharedWithMe) but it is giving error when I post the payload.
When I change the resource to OneDrive( me/drive/root) which Microsoft API recommends for subscriptions but that also giving error.
I set up the API permission for the app. Few of the application permission which needs admin consent but could not be done for the current user. User grants are given below.
I have created ngrok URL to redirect webserver http://localhost:5000 /notify to ngrok URL. This is mentioned in the payload for posting for a new subscription. Python code also is given below.
I want to know what is the prerequisite for the enabling subscription. Please provide light on license requirement, API permission and scopes, resource group, and azure key vault. This requirement is for OneDrive storage subscription.
Document referenced:
https://learn.microsoft.com/en-us/samples/microsoftgraph/aspnetcore-webhook-with-resource-data/sample-application---microsoft-graph-change-notifications/
When we are posting the payload for new subscriptions, it is giving error.
payload:
{
"changeType": "updated",
"notificationUrl": "https://d76209350b89.ngrok.io/notify",
"resource": "me/drive/root",
"expirationDateTime": "2020-07-24T18:23:45.9356913Z",
"clientState": "secretClientValue",
"latestSupportedTlsVersion": "v1_2"
}
subscriptions:
https://graph.microsoft.com/v1.0/subscriptions
{
"error": {
"code": "InvalidRequest",
"message": "Subscription validation request failed. Response must exactly match validationToken query parameter.",
"innerError": {
"date": "2020-07-22T16:45:41",
"request-id": "d5d7f05b-9f3d-44a9-a74a-9f21e3c8a9ba"
}
}
}
Endpoint that receives the validation request
enter code here:
http_header={'Authorization':f'Bearer
{token_response["accessToken"]}','Content-type':'application/json'}
print(http_header)
post_data={
"changeType": "updated",
"notificationUrl": REDIRECT_URI_2,
"resource": "me/drive/root",
"expirationDateTime": "2020-07-22T18:23:45.9356913Z",
"clientState": "secretClientValue",
"latestSupportedTlsVersion": "v1_2"
}
res=requests.post('https://graph.microsoft.com/v1.0/subscriptions',headers=http_header,data=post_data)
Receives the change notifications
#app.route("/notify",methods=['GET','POST'])
def onedrive():
valtoken=flask.request.args.get('validationToken')
valtok=valtoken.replace(':','%3a')
valt=valtok.replace(' ','+')
subscribe_url = f'https://062dece903f6.ngrok.io/notify?validationToken={valt} HTTP/1.1'
resp = flask.Response(status=200)
resp.headers['content-type']="plain/text"
resp.headers['token']=valt
resp.headers['location'] = subscribe_url
return resp
I am developing in Python. Anyone has done this before please share.
Thanks.
The content type should be text/plain. The validation token value should be returned as the response body and not a header. There's no need for a location header.
Also: I'm not sure why you are replacing characters but you should simply url decode and return as is.
valtoken=request.args.get('validationToken')
resp=app.response_class(valtoken,status=200,content_type="text/plain")
return resp
#app.route("/notify",methods=['POST'])
def onedrive():
valtoken=flask.request.args.get('validationToken')
resp=app.response_class(response=urllib.parse.unquote(valtoken),status=200,mimetype='plain/text')
return resp

Authentication fails on google home (oauth2)

I'm trying to connect to google home using OAuth2.0 mechanism. However, hitting with an issue where I'm not able to retrieve success message.
The failing request is - https://oauthintegrations.googleapis.com/v1/token:getForService
with the response payload as redirectState. I know about redirect but what is redirectState? I tried to search a bit over this one, but failed.
Any help would be appreciated.
Note:I have followed all the necessary steps mentioned in doc, I can receive authorisation code, but not able to make token request to desired endpoint.
The docs are https://developers.google.com/actions/identity/oauth2-code-flow and https://developers.google.com/actions/identity/account-linking.
In configuration settings we have Linking type as Oauth -> Authorization Code.
In dialog flow in Integration -> Integration Settings we have checked in for 'Sign in required' for Default Welcome Intent and have the firebase function as
app.intent('Default Welcome Intent', (conv) => {
conv.ask(new SignIn());
});
according to https://developers.google.com/actions/identity/account-linking document and I am currently using API version V2.
After the auth code is received as mentioned it does not call token url, we receive this screen :
Bad response from IdP in Auth Code Exchange & what is redirect_state
The https://gala-demo.appspot.com/app#redirect_state=XXX&state=yyy&service=abc when inspected fails at https://oauthintegrations.googleapis.com/v1/token:getForService as mentioned by #rajesh with status code 400, but when this request is made through postman it return the response. Here is the body and response for the request.
Body :
{
"credential" : {
"redirectState": "XXX"
},
"scopes": [],
"gdiState": "APP_AUTH",
"serviceId": "tapclicks-integration-adac2_dev"
}
RESPONSE :
{
"serviceInfo": {
"authUrl": "https://-domain-/authorization",
"name": "tapclicks dashboard",
"logoUrl": "https://placeholder.com/",
"clientId": "zdqexVMaVvxIMQ7Frjwa",
"tokenUrl": "https://-domian-/token_url",
"privacyPolicyUrl": "https://placeholder.com/",
"tosUrl": "https://placeholder.com/",
"id": "tapclicks-integration-adac2_dev"
},
"completionInfo": {
"appauthInfo": {
"appauthRedirectUrl": "https://-domain-/authorization?response_type=code&client_id=zdqexVMaVvxIMQ7Frjwa&redirect_uri=https://oauth-redirect.googleusercontent.com/r/tapclicks-integration-adac2&scope=gmail&state=yyy",
"appauthRedirectState": "abcxxx"
},
"oauthAuthorizationUrl": "https://-domain-/authorization?response_type=code&client_id=zdqexVMaVvxIMQ7Frjwa&redirect_uri=https://oauth-redirect.googleusercontent.com/r/tapclicks-integration-adac2&scope=gmail&state=yyy"
},
"gdiState": "APP_AUTH",
"header": {}
}
Can you please tell if i might be making any configuration mistake or any other info you need.
Authorization Url : https://kprb95tye7.execute-api.us-east-1.amazonaws.com/authorization/
Token Url : https://9343j46f16.execute-api.us-east-1.amazonaws.com/token_url/
Thanks

Create a draft reply message give an error on providing payload

I am hitting the Outlook Office 365 API through Postman. I tried to create a draft reply message using this URL:
POST https://outlook.office.com/api/v2.0/me/messages/{message_id}/createreply
The body contained:
body: {
"Comment": "Sounds great! See you tomorrow."
}
but I got the following error:
{
"error": {
"code": "RequestBodyRead",
"message": "The parameter 'Comment' in the request payload is not a valid parameter for the operation 'CreateReply'."
}
}
I have used this call based on the documentation.
This issue also exists for create a draft reply all message and create a draft forward message.
This is because you're placing comment within the body, it should stand on it's own. From this documentation:
POST https://outlook.office.com/api/beta/me/messages/AAMkADA1MTAAAAqldOAAA=/createreply
Content-Type: application/json
{
"Comment": "Fanny, Randi, would you name the group if the project is approved, please?"
}
Note that it is {"comment": "string"} and not body:{"comment": "string"}.

Resources