Actionable Messages with HTTP Post in Outlook and new SPFx WebPart - json

I have created an Actionable Message and registered a provider in Office365, which is approved for my organization. I'm sending the message via Microsoft Flow.
The message contains HttpPost actions in which I want to receive the response with am HTTP triggered Flow.
This is the JSON of the actionable message (I've removed the FLOW urls, and #'s are escaped.):
{
"##type": "MessageCard",
"##context": "http://schema.org/extensions",
"originator": "<my_provider_id>",
"summary": "Klanttevredenheidsonderzoek ",
"title": "Bent u tevreden over de afhandeling van **melding 92138749247**",
"text": "Graag horen we of u tevreden bent over deze melding",
"themeColor": "E81123",
"sections": [
{
"potentialAction": [
{
"##type": "HttpPOST",
"name": "Slecht!",
"headers": [{ "Content-Type": "application/json" }],
"target": "<flowurl>?<>flowurlparameters",
"body": "Slecht!"
},
{
"##type": "HttpPOST",
"name": "Goed!",
"headers": [{ "Content-Type": "application/json" }],
"target": "<flowurl>?<>flowurlparameters",
"body": "Goed"
}
]
},
{
"startGroup": true,
"title": "**Disclaimer**",
"text": ". 2018"
}
]
}
I have two problems:
If I mail my own O365 account, I get the mail with the message
showing correctly. However, the post buttons do not work correctly,
and the link I see when I hover over the buttons is missing the URL
parameters (which might be the cause it's not working). What could I
be doing wrong, or is it still too early for this to work? How can I
debug this?
In the new SPFx O365Connectors webpart the HTTPPost actions are missing completely. The rest of the message is shown correctly. Are HTTPPost actions not supported yet? Or will they not be supported at all? Or is something wrong with what I'm doing..?

Microsoft has now added support for the scenario of catching HTTP Post operations from within an actionable email by Microsoft Flow. The key is to explicitly set the authorization header to an empty string.
Below snippet uses the adaptive card schema v1.0 at http://adaptivecards.io/schemas/adaptive-card.json
"actions": [
{
"type": "Action.Http",
"title": "Light",
"method": "POST",
"headers": [
{
"name": "Authorization",
"value": ""
}
],
"url": "<a http triggered Flow URL>",
"body": "{'currentRoom':'room1','currentState':'roomState1','action':null,'exit':null,'object':null,'objectAction':null,'userEmail':'someuser#somedomain.com'}"
}
]

I received the following response from a Microsoft employee regarding this issue:
The reason it fails is because the logic app doesn’t allow sending
Authorization header and it responds back 401 Unauthorized. We send
Authorization header to identify that the request is from Office 365.
The logic app works fine without Authorization header.
I will discuss this with the team and see if we can resolve this kind
of scenario, and will update you on the status.
So for now it seems this scenario is not supported.

Related

In MS Team Adaptive Card, how do I specify the server it post to?

I am trying to use Action.Submit in my adaptive card to hit my Google Cloud Function. Where do I specify where to send the submission to? The reason I am doing this is I want to skip building a full chat server due to time constraint.
Example of Adaptive Card, no property to specify post URL:
{
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"type": "AdaptiveCard",
"version": "1.0",
"body": [
{
"type": "TextBlock",
"text": "Present a form and submit it back to the originator"
},
{
"type": "Input.Text",
"id": "firstName",
"placeholder": "What is your first name?"
},
{
"type": "Input.Text",
"id": "lastName",
"placeholder": "What is your last name?"
}
],
"actions": [
{
"type": "Action.Submit",
"title": "Action.Submit",
"data": {
"x": 13
}
}
]
}
Adaptive cards aren't developed specifically for bot service.
so working with them needs some tricks , in your case if you are trying to send a request that contain adaptive card inputs you need to know :
when the user click the submit button the adaptive card will send a message to bot activity handler on behalf of the user, this message contains a JSON object (you can view this object by adding this line in the bot onMessage function.
console.log(context.activity)
you can get the data from this meesage by using :
context.activity.value.firstName (to get the firstName sent by the adaptive card)
Now you can send your request to the server i prefer using Axios .

OneNote API Get Notebooks issue

The following is a sample schema from the OneNote API documentation at this site and will can be used with json2csharp.com with no problems.
http://dev.onenote.com/docs#/reference/get-notebooks.
{
"createdBy": "user name",
"createdTime": "2013-10-05T10:57:00.683Z",
"id": "notebook ID",
"isDefault": false,
"isShared": false,
"lastModifiedBy": "user name",
"lastModifiedTime": "2014-01-28T18:49:00.47Z",
"links": {
"oneNoteClientUrl": {
"href": "onenote:https://{client URL}"
},
"oneNoteWebUrl": {
"href": "https://{web URL}"
}
},
"name": "notebook name",
"sectionGroupsUrl": "https://www.onenote.com/api/v1.0/notebooks/{notebook ID}/sectionGroups",
"sectionsUrl": "https://www.onenote.com/api/v1.0/notebooks/{notebook ID}/sections",
"self": "https://www.onenote.com/api/v1.0/notebooks/{notebook ID}",
"userRole": "Contributor"
}
However, using the following Get Notebooks link has a different schema that doe
sn't pass json2csharp. Parsing your JSON didn't work. Please make sure it's valid.
"https://graph.microsoft.com/v1.0/me/onenote/notebooks"
createdBy and lastmodifiedBy are thrown as exceptions.
The sample from the apigee.com/console app uses the https://www.onenote.com/api/v1.0/me/notes/notebooks link and has the correct schema.
How do I resolve this discrepancy? Or am I mistaken?
The response payload returned from the Microsoft Graph API is slightly different from the response payload returned from the OneNote API directly.
Here's a reference to the notebook properties returned from Microsoft Graph: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/notebook
And this is what gets returned from the OneNote API directly:
https://msdn.microsoft.com/en-us/library/office/dn769050.aspx => Response properties

Parse Dynamic Property name in Azure Logic App

I have been playing around with Azure Logic Apps and trying to retrieve a Pocket (ReadItLater) article so that I can create a new task in my preferred Task Manager. I have Two HTTP Connectors (one for Retrieve Operation using Pocket API and another post data to Todoist (my preferred task manager).
I can retrieve the Article and the response looks like (removed a few properties below for easy reading):
{
"statusCode": 200,
"headers": {
"pragma": "no-cache",
"status": "200 OK"
},
"body": {
"status": 1,
"complete": 1,
"list": {
"586327616": {
"item_id": "586327616",
"resolved_id": "586327616",
"given_url": "http://kenwheeler.github.io/slick/?utm_source=hackernewsletter&utm_medium=email&utm_term=design&mc_cid=58c9499fa2&mc_eid=3aaf6c4e47",
"given_title": "slick - the last carousel you'll ever need",
"time_added": "1396652224",
"time_updated": "1405156517",
"resolved_title": "slick",
"resolved_url": "http://kenwheeler.github.io/slick/?utm_source=hackernewsletter&utm_medium=email&utm_term=design&mc_cid=58c9499fa2&mc_eid=3aaf6c4e47",
"excerpt": "Add slick.js before your closing <body> tag, after jQuery (requires jQuery 1.7 +) <script type=\"text/javascript\" src=\"slick/slick.min.",
"word_count": "22"
}
}
}
}
Now I want to parse the above response to retrieve individual article properties (i.e. resolved_title). The issue here is the object under the list "586327616" is dynamic and changes for every article, and I can't seem to parse this as an expression in Logic App. My current action in Logic App looks like:
"postToTodoist": {
"conditions": [
{
"expression": "#equals(outputs('getPocketArticles')['statusCode'], 200)"
},
{
"dependsOn": "getPocketArticles"
}
],
"inputs": {
"body": "#{outputs('getPocketArticles')['body']['list'][0]['resolved_title']}",
"headers": {
"Content-Type": "application/x-www-form-urlencoded"
},
"method": "POST",
"repeat": {},
"uri": "https://todoist.com/API/v6/add_item"
},
"type": "Http"
}
For the expression I have tried converting the response to string, using coalesce and trying to access using an index, but nothing seem to work. In the error, it tells me what that the available property is i.e.:
{"code":"InvalidTemplate","message":"Unable to process template language expressions in action 'postToTodoist' inputs at line '1' and column '11': 'The template language expression 'coalesce(body('getPocketArticles')['list']).resolved_title' cannot be evaluated because property 'resolved_title' doesn't exist, available properties are '586327616'. Please see https://aka.ms/logicexpressions for usage details.'."}
I feel that it is not possible to construct an expression without knowing the name of the property, has anyone done something similar?

Google image search api. Bad request

I'm using Google CustomSearch API v1 for image search but I have a problem with my JSON request.
When I filled out the search.cse.list (here) I got the JSON request like this:
GET https://www.googleapis.com/customsearch/v1?q=test&cref=AIzaSyAreDhTh3IqaGPqC44t08sQF_qbSGzzA7Q&cx=010855067127206535986%3Aqdh_vhglb4u&fileType=jpg&filter=1&imgSize=medium&imgType=news&num=4&searchType=image&start=1&key={YOUR_API_KEY}
And the response of this request:
{
"kind": "customsearch#search",
"url": {
"type": "application/json",
"template": "https://www.googleapis.com/customsearch/v1?q={searchTerms}&num={count?}&start={startIndex?}&lr={language?}&safe={safe?}&cx={cx?}&cref={cref?}&sort={sort?}&filter={filter?}&gl={gl?}&cr={cr?}&googlehost={googleHost?}&c2coff={disableCnTwTranslation?}&hq={hq?}&hl={hl?}&siteSearch={siteSearch?}&siteSearchFilter={siteSearchFilter?}&exactTerms={exactTerms?}&excludeTerms={excludeTerms?}&linkSite={linkSite?}&orTerms={orTerms?}&relatedSite={relatedSite?}&dateRestrict={dateRestrict?}&lowRange={lowRange?}&highRange={highRange?}&searchType={searchType}&fileType={fileType?}&rights={rights?}&imgSize={imgSize?}&imgType={imgType?}&imgColorType={imgColorType?}&imgDominantColor={imgDominantColor?}&alt=json"
},
"queries": {
...
},
"context": {
...
},
"searchInformation": {
...
},
"items": [
{
"kind": "customsearch#result",
"title": "free student testing cartoons | Home > Clipart > Cartoons ...",
"htmlTitle": "free student <b>testing</b> cartoons | Home > Clipart > Cartoons <b>...</b>",
"link": "https://s-media-cache-ak0.pinimg.com/236x/30/0c/a5/300ca57d460ab787202e36bdf0364e57.jpg",
"displayLink": "www.pinterest.com",
"snippet": "free student testing cartoons",
"htmlSnippet": "free student <b>testing</b> cartoons",
"mime": "image/jpeg",
"image": {
"contextLink": "https://www.pinterest.com/pin/568157309212095926/",
"height": 213,
"width": 236,
"byteSize": 14426,
"thumbnailLink": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQ-JefdKWd1WZkuesaq01zldYRW2JmYd_z0cW0SF9OEXFMVr6M8XZO4kg",
"thumbnailHeight": 98,
"thumbnailWidth": 109
}
},
But when I tried to use this request at the browser bar I got an error:
{
"error": {
"errors": [
{
"domain": "usageLimits",
"reason": "ipRefererBlocked",
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed.",
"extendedHelp": "https://console.developers.google.com"
}
],
"code": 403,
"message": "There is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your API key configuration if request from this IP or referer should be allowed."
}
}
I guess that I should use Ajax call, but I dont know how can I do it, because I am beginner.
I also made an API Key, "cx" and have enabled CustomSearch API at my console.developer account.
So the question is: How can I get values from this JSON request and then operate with them if I even cant get values in my browser? I want to get an image-link from this request.
Sorry for my English.
The Google Image Search API was deprecated in 2011, and has finally, now, been switched off :( You'll have to find something else to use, sorry :(

How do I send Email with inline Attachments

I send the description my team is having with the json integration with Office API 365.
We want to send an email with inline attachments through the JSON API.
With that objective, what we are doing:
Create an empty draft message using reply operation;
Send the several inline attachments;
Update the body of the draft message (with cid images inline);
Send the message;
What is our issue with the API?
We are unable to set the "ContentType" properties when we submit the attachments to the Office API 365.
Despite the "ContentType" we send, it is always null.
We are using the following API: POST https://outlook.office365.com/api/v1.0/me/messages/{message_id}/attachments
That's the reason we think that despite the inline image then it is found in the body, it cannot be displayed because the contenttype it is not set correctly.
Please give us some direction.
The ContentType shouldn't be an issue. What is important is that you set the ContentId property to a value, then use that value in your cid link in the message body. Here's what worked for me:
POST /Me/folders/drafts/messages
{
"Subject": "Inline image test",
"Body": {
"ContentType": "HTML",
"Content": "<html><body><strong>There should be an image here:</strong><p><img src=\"cid:my_inline_attachment\"></p></body></html>"
}
}
Notice the cid:my_inline_attachment bit.
Then do:
POST /Me/messages({message_id})/Attachments
{
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"Name": "th.jpg",
"IsInline": true,
"ContentId": "my_inline_attachment",
"ContentBytes": {base64-encoded contents of jpeg}
}
Notice the "ContentId": "my_inline_attachment" line in the attachment JSON. Hope that helps!
Doing a draft and adding an attachment is not very efficient and introduce a lot of point of failure.
Fortunately, this can be one all in one go.
Here is an example with 1 image. That can be pasted in Graph Explorer: https://developer.microsoft.com/graph/graph-explorer/
URL: https://graph.microsoft.com/v1.0/me/sendMail (as Post)
Change the email from to be yours. Notice the contentBytes is a base64 of the image. It's a jpeg, but this also works with png.
Pay attention to the cid, it should be a unique id for your images.
{
"message": {
"subject": "Test graphAPI",
"toRecipients": [{ "emailAddress": {"address": "youremail#outlook.com"}}],
"body": {
"contentType": "html",
"content": "<div>This is a small jpeg: <img src=\"cid:yourcid\"></div>"
},
"attachments": [
{
"contentType": "image/jpg",
"contentId": "yourcid",
"isInline": true,
"#odata.type": "#Microsoft.OutlookServices.FileAttachment",
"contentBytes": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAsICAoIBwsKCQoNDAsNERwSEQ8PESIZGhQcKSQrKigkJyctMkA3LTA9MCcnOEw5PUNFSElIKzZPVU5GVEBHSE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