How can I create a calendar event on Outlook with Microsoft Graph API? - node.js

I have an app that integrates with Office365 and I am attempting to create a calendar event on an Outlook calendar using the Microsoft Graph API. Here is what I have so far:
request.post({
url:'https://graph.microsoft.com/v1.0/me/events',
form: {
"Id": null,
"Subject": "Discuss the Calendar REST API",
"Body": {
"ContentType": "Text",
"Content": "This is some content."
},
"Start": {
"DateTime": "2016-01-24T18:00:00",
"TimeZone": "Pacific Standard Time"
},
"End": {
"DateTime": "2016-01-25T19:00:00",
"TimeZone": "Pacific Standard Time"
},
"ShowAs": "Free",
"IsReminderOn":false
},
headers: {
"Authorization": "Bearer " + access_token,
"Content-Type": "application/json"
}
}, function(err, httpResponse, body) {
if (err) {
console.log('addMicrosoftAccessToken() ERROR = ' + err);
callback(err, false);
} else {
console.log('httpResponse = ' + JSON.stringify(httpResponse));
callback(null, true);
}
})
The problem is that the event isn't saved on the users Outlook calendar. Also, I'm not getting an error in the log. I suspect that I'm not sending the proper form data in the request. Any ideas?
UPDATE: Here is the httpResponse I'm getting in the log:
{
"statusCode": 500,
"body": "{\r\n \"error\": {\r\n \"code\": \"UnknownError\",\r\n \"message\": \"\",\r\n \"innerError\": {\r\n \"request-id\": \"8ebe2efc-649c-4d8d-bee1-be2457cc3a45\",\r\n \"date\": \"2016-01-25T19:05:27\"\r\n }\r\n }\r\n}",
"headers": {
"cache-control": "private",
"transfer-encoding": "chunked",
"content-type": "application/json",
"server": "Microsoft-IIS/8.5",
"request-id": "8ebe2efc-649c-4d8d-bee1-be2457cc3a45",
"client-request-id": "8ebe2efc-649c-4d8d-bee1-be2457cc3a45",
"x-ms-ags-diagnostic": "{\"ServerInfo\":{\"DataCenter\":\"East US\",\"Slice\":\"SliceB\",\"ScaleUnit\":\"000\",\"Host\":\"AGSFE_IN_4\",\"ADSiteName\":\"EST\"}}",
"outboundduration": "707.5019",
"duration": "713.2419",
"x-powered-by": "ASP.NET",
"date": "Mon, 25 Jan 2016 19:05:27 GMT",
"connection": "close"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "graph.microsoft.com",
"port": 443,
"hostname": "graph.microsoft.com",
"hash": null,
"search": null,
"query": null,
"pathname": "/v1.0/me/events",
"path": "/v1.0/me/events",
"href": "https://graph.microsoft.com/v1.0/me/events"
},
"method": "POST",
"headers": {
"Authorization": "Bearer blah blah",
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
"content-length": 643
}
}
}
UPDATE 2:
This link is titled "Create Event", and appears to have the response listed in both the request and response sections, making it particularly confusing:
http://graph.microsoft.io/docs/api-reference/v1.0/api/event_post_instances
Also, in the above link where it lists
POST https://graph.microsoft.com/v1.0/me/events/<id>/instances
what is <id>? It doesn't tell me what id is supposed to be?
UPDATE 3: This link is also titled "Create Event", yet it has a different POST URL:
http://graph.microsoft.io/docs/api-reference/v1.0/api/user_post_events
Very confusing.

The reason why your me/events request fails is that you used the Azure Active Directory (AAD) authorization flow for accessing your personal Microsoft Account (Live Id) calendar. AAD allows creating users mapped to Microsoft Accounts such that when requesting an AAD token you're signing in with your Microsoft Account credentials. That way your credentials can be used to access both business (work or school) and consumer (personal) services. While the credentials are shared there are 2 distinct user accounts. When accessing business services like OneDrive for Business or SharePoint you need to sign in with the AAD user account in the context of your work or school organization. When accessing consumer services like Hotmail or OneDrive you need to sing in with the Microsoft Account (Live Id). You request is attempting to access an Outlook account in the context of your organization, which doesn't exist as your email address is already served by a personal Outlook account associated with your Microsoft Account. Please use the converged authorization flow (http://graph.microsoft.io/en-us/docs/authorization/converged_auth) to sign in with your personal Microsoft Account and you'll be able to access your personal email and calendar. Alternatively you can keep using the AAD authorization flow to access work or school calendars for AAD users not mapped to Microsoft Accounts.

Related

Azure Translator API always gives me 404

I'm trying to use translator API through a free trial subscription. After creating it, I set resource groups and add cognitive service to it. On that cognitive service page, I followed the "Quick Start" guide and got a pair of keys and ENDPOINT url.
Then I followed this document. It says an API key and endpoint are needed to use translator API. And I get them from RESOURCE MANAGEMENT>Keys and Endpoint section.
https://learn.microsoft.com/en-gb/azure/cognitive-services/translator/quickstart-translate?pivots=programming-language-javascript
But I always get 404 status code from this API every time I send a request. Is there anything I do wrong? How can I use this API?
SubscriptionID: zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
My code:
const subscriptionKey = 'my-sub-key'; // There are two keys, key1 and key2. I use key1 here.
const endpoint = 'https://japaneast.api.cognitive.microsoft.com/';
const options = {
method: 'POST',
baseUrl: endpoint,
url: 'translate',
qs: {
'api-version': '3.0',
'to': 'en'
},
headers: {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Content-type': 'application/json',
'X-ClientTraceId': uuidv4().toString()
},
body: [{
'text': 'hello world'
}],
json: true,
};
request(options, function (err, resFromMicrosoft, body) {
res.json(resFromMicrosoft);
}
Error response:
{
"statusCode": 404,
"body": {
"error": {
"code": "404",
"message": "Resource not found"
}
},
"headers": {
"content-length": "56",
"content-type": "application/json",
"apim-request-id": "e2ae69cc-b93c-4db2-aef4-47096eb3ec61",
"strict-transport-security": "max-age=31536000; includeSubDomains; preload",
"x-content-type-options": "nosniff",
"date": "Fri, 19 Jun 2020 06:11:24 GMT",
"connection": "close"
},
"request": {
"uri": {
"protocol": "https:",
"slashes": true,
"auth": null,
"host": "japaneast.api.cognitive.microsoft.com",
"port": null,
"hostname": "japaneast.api.cognitive.microsoft.com",
"hash": null,
"search": "?api-version=3.0&to=en",
"query": "api-version=3.0&to=en",
"pathname": "/translate",
"path": "/translate?api-version=3.0&to=en",
"href": "https://japaneast.api.cognitive.microsoft.com/translate?api-version=3.0&to=en"
},
"method": "POST",
"headers": {
"Ocp-Apim-Subscription-Key": "my-sub-key",
"Content-type": "application/json",
"X-ClientTraceId": "8eedf6f4-db0c-45cb-a95b-92a2797df067",
"accept": "application/json",
"content-length": 83
}
}
}
As mentioned in the documentation, please use the global endpoint - https://api.cognitive.microsofttranslator.com/
I saw your comment about getting 401 after using the global endpoint.
You still need to use the global endpoint as mentioned by Swetha.
This might help https://github.com/MicrosoftDocs/azure-docs/issues/57430#event-3480744006
(From the above page)
"It looks like you are using a common cognitive service resource and a key. Most the services have moved to using an individual resource type and if you can create and use the translator resource the steps mentioned in the documentation should work as is."

insert row in Azuresqldatabase by using Azure Logic Apps

I am having Azure SQL database and I want to perform Insert,Update,Delete Operations by using Logic Apps
and is it necessary to have a gateway while Connecting to Azure SQL DB to Sqlserver Connector in Logic -app I have Three properties 1)Id 2)Name 3)Department in Azure SqlDB
**When HTTP Request is Received Code:**
{
"headers": {
"Accept": "application/json",
"Content-Type": "application/json"
},
"properties": {
"Department": {
"type": "string"
},
"Name": {
"type": "string"
},
"id": {
"type": "integer"
}
},
"type": "object"
}
Http Request is Received
In sql Connector it showing Bad request:
Insert -row Connector
The Body element of properties are null
{ "Department": null, "Name": null, "id": null }
The Output of Insert Row Connector
{
"statusCode": 400,
"headers": {
"Pragma": "no-cache",
"x-ms-request-id": "3332d425-3e10-4f04-b618-63f359168acc",
"Strict-Transport-Security": "max-age=31536000; includeSubDomains",
"X-Content-Type-Options": "nosniff",
"X-Frame-Options": "DENY",
"Timing-Allow-Origin": "*",
"x-ms-apihub-cached-response": "false",
"Cache-Control": "no-store, no-cache",
"Date": "Mon, 04 May 2020 08:16:24 GMT",
"Content-Length": "468",
"Content-Type": "application/json",
"Expires": "-1"
},
"body": {
"status": 400,
"message": "Microsoft SQL: Cannot insert the value NULL into column 'id', table '.dbo.Details'; column does not allow nulls. INSERT fails.\r\nclientRequestId: 3332d425-3e10-4f04-b618-63f359168acc",
"error": {
"message": "Microsoft SQL: Cannot insert the value NULL into column 'id', table 'dbo.Details'; column does not allow nulls. INSERT fails."
},
"source": "sql-eus2.azconn-eus2.p.azurewebsites.net"
}
}
Note:I am not using any gate-way please guide me on the above task if you have any resource please let me
know
Logic App-Defination:
Designer
previous error history:
error:
data I am Passing in Payload schema:
enter image description here
The error is occurring because you are running the trigger from the azure portal. See when I run the trigger as shown in the image below,
And I encounter following error
"Microsoft SQL: Cannot insert the value NULL into column 'id', table 'librarymanagement.dbo.DepartmentTable'; column does not allow nulls. INSERT fails."
To properly invoke the HTTP trigger Logic APP, you need to make a HTTP API call to it. If you are just learning, you can use POSTMAN to make the call. Following are the steps you need to do
Copy the Logic APP url from the portal.
Create a new request in postman and select POST method and paste the url copied in step 1. Also paste the body as shown.
Now move to Headers and Set the values as shown below.
Click on Send

How to handle the graph v1 event with attendees when user's outlook is not verified to send email?

I am creating new graph event with graph-v1 with "openTypeExtension" and "attendees" but when i create event for user who has not verified outlook to send email then it gives me 403 error.
I handled it in catch block for my database but after failing request-promise for API call it creates new event at Microsoft calendar and sends me back in web-hook without containing my extensions. So, it can't identify the event and web-hook's method stores it as new event.
Here is my code for API request-promise:
var options = {
method: 'POST',
uri: 'https://graph.microsoft.com/v1.0/me/events',
headers: {
Authorization: 'Bearer ' + [ACCESS_TOKEN],
'content-Type': 'application/json',
},
body: JSON.stringify({
"subject": agenda.title,
"body": {
"contentType": "HTML",
"content": ""
},
"start": {
"dateTime": agenda.start.time,
"timeZone": agenda.start.timeZone
},
"end": {
"dateTime": agenda.end.time,
"timeZone": agenda.end.timeZone
},
"location": {
"displayName": [NAME]
},
"extensions": [
{
"#odata.type": "microsoft.graph.openTypeExtension",
"extensionName": [EXT_NAME],
"agendaId": [ID]
}
],
"attendees": [
{
"emailAddress": {
"address": [EMAIL]
},
"type": "required"
}
]
}),
};
I am getting this error :
{ StatusCodeError: 403 - "{\r\n \"error\": {\r\n \"code\":
\"ErrorMessageSubmissionBlocked\",\r\n\"message\": \"Cannot send mail.
Follow the instructions in your Inbox to verify your
account.\",\r\n\"innerError\": {\r\n \"request-id\":
\"bec4fcaf-7eaa-4473-a53d-6cab6b2c8b8c\",\r\n
\"date\"\"2019-01-22T07:42:01\"\r\n }\r\n }\r\n}", name:
'StatusCodeError', statusCode: 403, message: '403 - "{\r\n
\"error\": {\r\n \"code\":
\"ErrorMessageSubmissionBlocked\",\r\n \"message\": \"Cannot
send mail. Follow the instructions in your Inbox to verify your
account.\",\r\n \"innerError\": {\r\n \"request-id\":
\"bec4fcaf-7eaa-4473-a53d-6cab6b2c8b8c\",\r\n \"date\":
\"2019-01-22T07:42:01\"\r\n }\r\n }\r\n}"', error: '{\r\n
"error": {\r\n "code": "ErrorMessageSubmissionBlocked",\r\n
"message": "Cannot send mail. Follow the instructions in your Inbox to
verify your account.",\r\n "innerError": {\r\n "requestid":
"bec4fcaf-7eaa-4473-a53d-6cab6b2c8b8c",\r\n "date":
"2019-01-22T07:42:01"\r\n }\r\n\r\n}'
....
.... }
for that I handled it with 'statusCode' in catch() for my database but after this call fails I am getting 'webhook' call for new event generated from 'Microsoft calendar' which doesn't contain my extension so it behaves as 'Microsoft event' not my application 'Agenda event'.
So, Is there any I prevent the new event at 'Microsoft calendar' or Any solution for my extensions?
The same problem occurred to me as well.
for resolution, you are suppose to go to your MICROSOFT account portal and login.
at the time of login it will ask you to verify your mobile number.
as soon as you will verify it, you will be able send email perfectly.

Azure AD with external accounts and Microsoft Graph API

We are setting up Microsoft Azure Active Directory as an SSO solution for our mobile app but want to manage the account creation for users via the server side Microsoft Graph API.
For internal users of the domain, this works perfectly as we are using the Graph API as an admin user to create the accounts.
But, when trying to create an external account, (say joe.bloggs#gmail.com), this fails.
We are using the API call:
POST https://graph.microsoft.com/v1.0/users
BODY:
{
"accountEnabled": true,
"mailNickname": "joe.bloggs",
"displayName": "Joe Bloggs",
"givenName": "Joe",
"surname": "Bloggs",
"userPrincipalName": "joe.bloggs#gmail.com",
"passwordProfile" : {
"forceChangePasswordNextSignIn": false,
"password": "somepassword"
}
}
RESPONSE:
{
"error": {
"code": "Request_BadRequest",
"message": "Property userPrincipalName is invalid.",
"innerError": {
"request-id": "619450ec-e703-4a12-86e3-8f53c20d55fc",
"date": "2018-01-17T16:30:37"
},
"details": [
{
"target": "userPrincipalName",
"code": "InvalidValue"
}
]
}
}
It is saying the "userPrincipalName" is invalid, but after reviewing the documentation I'm not sure if the API supports external accounts or not?
NOTE: I realise you can use the "/beta/invitations" call but this does not create accounts.
I assume that you'r using Azure AD B2B and want to add new guest users to your Directory.
One thing I want to make clear is that you can invite guest users to your Directory , but you cannot create guest users directly in your Directory.
So, you can invite guest users with this Microsoft Graph API:
Request
POST https://graph.microsoft.com/beta/invitations
Content-type: application/json
Content-length: 551
{
"invitedUserEmailAddress": "yyy#test.com",
"inviteRedirectUrl": "https://myapp.com"
}
Response
HTTP/1.1 201 OK
Content-type: application/json
Content-length: 551
{
"id": "7b92124c-9fa9-406f-8b8e-225df8376ba9",
"inviteRedeemUrl": "https://invitations.microsoft.com/redeem/?tenant=04dcc6ab-388a-4559-b527-fbec656300ea&user=7b92124c-9fa9-406f-8b8e-225df8376ba9&ticket=VV9dmiExBsfRIVNFjb9ITj9VXAd07Ypv4gTg%2f8PiuJs%3d&lc=1033&ver=2.0",
"invitedUserDisplayName": "yyy",
"invitedUserEmailAddress": "yyy#test.com",
"sendInvitationMessage": false,
"invitedUserMessageInfo": {
"messageLanguage": null,
"ccRecipients": [
{
"emailAddress": {
"name": null,
"address": null
}
}
],
"customizedMessageBody": null
},
"inviteRedirectUrl": "https://myapp.com/",
"status": "Completed",
"invitedUser": [ { "id": "243b1de4-ad9f-421c-a933-d55305fb165d" } ]
}
Additional, if you want to invite guest users without an invitation, please refer to this document.
Hope this helps!

Creating a calendar event on windows live REST API

I'm always getting time-outs (60sec) after making a post to create an event.
URL: https://apis.live.net/v5.0/me/events
JSON: {
"id": "",
"name": "Google 3",
"description": "mychild event",
"calendar_id": "calendar.c988c1d9bf3dcf4b.adasdasdeqe3231q23",
"start_time": "2014-04-30T08:30:00-05:00",
"end_time": "2014-04-30T09:30:00-05:00",
"is_all_day_event": false,
"visibility": "public"
}
I pass the access_token on the http headers with the format: Authorization: Bearer + AccessToken.
I've successfully created this very same event using the ISDK.
What I'm doing wrong? Any hint?
Tks,

Resources