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/2wBDAAsICAoIBws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oBmBjltRcsJBjM/AYRnA3LtGe/3e2DW2GqPlUZO71Iqx1ukS+OF1K11KK4tIrJ7a8iS3ZrmYR7HQu4O4soXgkg56r2OM4Savd/LI1kt8IwrxQLq0MrAE8YRBucjAPzBiuM8da1vFnjLTdQ0+90u2jjukdShma4Ea7hgqUxkthh3wDjuDmuWjv8AV082KHUrNluOly1+T5Stg4Cu+RjpkruHNVWpw3a1fnYISkuo/wAQ+M4tW0j7HbWzo0uDMZMYXBBwuOvI6nHHbnjE0/VQniK21PUjLceXOs0hRgGOCCMZ44wOOOBjjqNKXSdJ0+CBGv7e8uZGLSMkg2RqFwV69SzAgnsvbHNFreKxmju9PvoxNbsJEDMpO5eQR68gcYrShTgoXprQJ88tWf/Z",
"name": "name.jpg"
}
]
}
}
Related
I'm looking to send out a Post json request using Zapier's webhook function, together with Slack's incoming webhook set up.
I'm using block kit to develop the message style, and so far that's worked great. However, I'd like my bot to display with a custom username and emoji/icon and I'm having trouble.
Here is the JSON payload I'm trying, based off this tutorial https://api.slack.com/methods/chat.postMessage#args
The post seems to ignore the first two lines and posts as the standard bot name
{
"as_user": false,
"username": "test",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*78 Varet St #14*\n 2 Bed / $2300 \n <#ben> \n 3rd Deposit This Month"
},
"accessory": {
"type": "image",
"image_url": "https://p.sharinpix.com/3/3521a32/YXBwLnNoYXJpbnBpeC5jb20vaW1hZ2VzL2I2M2RkZTY4LWZkMDMtNGZlYy04OGUxLWYwZjA0N2E4NjQ3NS90aHVtYm5haWxzL29yaWdpbmFsLWI5MTdlNzAzY2U2LmpwZw/77-varet-st-building.jpg?timestamp=1639154285",
"alt_text": "cute cat"
}
},
{
"type": "divider"
}
]
}
Any help would be greatly appreciated!
If you just want to modify the icon and name of your bot ( will be the same throughout the app ), you should be able to do that on https://api.slack.com/apps/{YOUR_APP_ID}/general? under the Display Information section.
If you want to be able to change it from message to message, you will have to grant your app additional permissions scopes. See https://api.slack.com/methods/chat.postMessage#authorship
Using PowerShell's Invoke-RestMethod, I have successfully been able to make a call to "https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/chatThreads" to post a message to my desired Team/Channel in a very neatly formatted way.
What I am now struggling with is #mentioning a user in the same message. I've followed the short tutorial on https://myteamsday.com/2019/03/05/sending-message-with-atmention-onto-a-channel-using-graphapi/
I get to the point where I added the mentions section to the body of the request, complete with id of the user and id of the mention.
Once I make the call, the message is posted but only the text as show in the content property. No link/mention to the actual user.
{
"rootMessage": {
"body": {
"contentType": "html",
"content": "Hello, World! <at id=\"0\">Jack Black</at>"
},
"mentions": [ {
"id": 0,
"mentionText": "Jack Black",
"mentioned": {
"id": "ac5e5x81-39Dd-4748-beTa-b5cd6t93ba67",
"displayName": "Jack Black",
"userIdentityType": "aadUser"
}
}
]
}
}
Here's one thing I noticed in the tutorial though, the guy references "https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/messages" , but Microsoft Graph references "https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/chatThreads"
When I replace chatThreads with message in Microsoft Graph, I get an Bad Request error message complaining about the content property cannot be null, but it is NOT null.
EDIT 1:
When using https://graph.microsoft.com/beta/teams/{team-id}/channels/{channel-id}/messages on graph explorer
{
"error": {
"code": "BadRequest",
"message": "Value cannot be null.\r\nParameter name: Content",
"innerError": {
"request-id": "f0d4fed8-7726-4338-8a68-9685a690eab5",
"date": "2019-07-02T12:46:14"
}
}
}
You need to include entities, with type 'mention', in your message and the message of the text should include <at>username</at> for each entity mentioned.
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.
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?
I'm using this Mozilla ADD-ON to post the data in mailgun API
RestClient
Content-Type:application/json
URL I'm using
https://api.mailgun.net/v2/sandbox42924.mailgun.org/messages
Json Data I'm posting
[
{
"from": "Kaushik <kaushik#gmail.com>"
},
{
"to": "Kaushik <kaushikfb1#gmail.com>"
},
{
"subject": "Hello This is test mail"
},
{
"text": "Testing some Mailgun !"
},
{
"html": "<html>Hello These <h2>contents belongs</h2> to html content</html>"
}
]
OR
{
"from": "Kaushik <kaushik#gmail.com>",
"to": "Kaushik <kaushikfb1#gmail.com>",
"subject": "Hello This is test mail",
"text": "Testing some Mailgun !",
"html": "<html>Hello These <h2>contents belongs</h2> to html content</html>"
}
In both cases what I'm getting is
{
"message": "'from' parameter is missing"
}
I want to know how i can post the data.
In documentation they have not describe this process.
I'm curious to know how it is working?
Here is the link for the documentation Click Here. They are using library for using in each language. If you know the library in detail you can help.
Finally I found the answer of this so for the sake of other user so they may find a help from this post in future I'm submitting the answer.
the url is this one.
https://api.mailgun.net/v2/yourdoamin.com/messages
username = api
password = {your key}
Now after that set your content type:application/x-www-form-urlencoded.
Now post the data. for formatting the data you can use this link Click Here
Demo data format
from%3D%27Excited%20User%20%3Cme%40yourdoamin.com%3E%27%20%5C%0A%20%20%20%20%20to%3Dbaz%40example.com%5C%0A%20%20%20%20%20to%3Dbar%40example.com%20%5C%0A%20%20%20%20subject%3D%27Hello%27%20%5C%0A%20%20%20%20text%3D%27Testing%20some%20Mailgun%20awesomness!%27