Graph API Unable to read JSON request payload - microsoft-graph-api

In power automate using Invoke an HTTP request, I am unable to make a graph API call for email sent(Post: https://graph.microsoft.com/v1.0/me/sendMail) with a customized email body (HTML elements and tags). It does not allow the below custom HTML code and errors as "Unable to read JSON request payload. Please ensure the Content-Type header is set and payload is of valid JSON format."  Please find the code below. In addition, HTML code is
Please find the code below.
And HTML Code is

This error occurs because your payload is not in a valid json format. You have to escape the quotation marks. Use \" intead of ".
{
"data": "<html><head>The title attribute example</head><body><h3 title=\"Hello HTML!\">Titled head tag example</h3></body></html>"
}

Like #Optimal already mentioned. It is good to escape the quotation marks of the HTML Body value.
However, I see the request body also has a saveToSentItems boolean property. Can you try it with that boolean as well?
Try something like below:
{
"message": {
"subject": "#{triggerBody()['text']}",
"body": {
"contentType": "HTML",
"content": "#{triggerBody()['text_1']}"
},
"toRecipients": [
{
"emailAddress": {
"address": "#{triggerBody()['text_2']}"
}
}
]
},
"saveToSentItems": "true"
}

Related

Filter event objects by body content

I'm trying to query calendar events using the Graph API and I would like to filter them by category and body content.
The goal is to get any event object that is in category "Test" and contains the string "FooBar" in its body content.
I tried to query the Graph API with the following request:
https://graph.microsoft.com/v1.0/me/events?$filter=(categories/any(x:x eq 'Test') and contains(body/content, 'FooBar'))
The response is a 500 error message:
{
"error": {
"code": "ErrorInternalServerError",
"message": "An internal server error occurred. The operation failed.",
//...
}
}
The "categories" filter clause works fine on its own but as soon as I put the "body/content" clause back in I get the aforementioned error response.
The json object I get from the Graph API looks like this (stripped down for better readability)
{
"value": [
{
"categories": [
"Test"
],
"bodyPreview": "FooBar",
"body": {
"contentType": "html",
"content": "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><div class=\"BodyFragment\"></div><div class=\"BodyFragment\"><font size=\"2\"><span style=\"font-size:11pt\"><div class=\"PlainText\">FooBar</div></span></font></div></body></html>"
}
}
]
}
Is there something wrong with my filter clause or might this be an issue with Graph API itself?
I first tried to filter by bodyPreview but the error response I got clearly said that this field cannot be filtered by so I guess body/content should be possible.
The filtering by body/content is not supported for events.
I've tried similar query for messages and it works fine, so your filter clause is correct.
GET https://graph.microsoft.com/v1.0/me/messages?$filter=(categories/any(x:x eq 'Test') and contains(body/content, 'FooBar'))

Outgoing Webhook what is the format of the response message?

I have created an outgoing webhook in MS Teams. At mentioning the name specified in the outgoing webhook, it will successfully cause an API call in my app - all fine and good.
According to the documentation, my app is required to respond to that request with a response message. But I absolutely can't find any documentation of the format that is accepted in this response.
The only reference, I can find is this one:
https://learn.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-outgoing-webhook
Unfortunately, it does not go into detail of what such a message can look like. It only gives an example that this would be acceptable:
{
"type": "message",
"text": "This is a reply!"
}
I would however not like to respond with a simple message, but much rather with something more rich formatted like a card or - in some cases a reaction instead of a message.
Is that possible? Is there any documentation, what other responses are acceptable? Are there other types than just "message" that can be returned?
Alright, here's a quick and dirty way to handle things for teams. For some reason this is not documented very clearly, but what teams requires is for the "Card" to be created as an attachment, instead of just getting the response directly.
What I've done is capture the boilerplate required to house the card first:
string TeamsAdaptiveCardBoilerplate =
#"
{
""type"":""message"",
""attachments"":[
{
""contentType"":""application/vnd.microsoft.card.adaptive"",
""contentUrl"":null,
""content"":{
""$schema"":""http://adaptivecards.io/schemas/adaptive-card.json"",
""type"":""AdaptiveCard"",
""version"":""1.2"",
""body"":[
##BODY##
]
}
}
]
}
";
Then, I build the body (usually, this would not be static text, but it serves well as an example)
string AdaptiveCardBody =
#"
{
""type"": ""TextBlock"",
""text"": ""Here is a ninja cat""
},
{
""type"": ""Image"",
""url"": ""http://adaptivecards.io/content/cats/1.png""
}
";
Next I simple swap out the placeholder with the real body:
var jsonPayload1 = TeamsAdaptiveCardBoilerplate.Replace("##BODY##", AdaptiveCardBody);
And finally, return the assembled payload (converted back into an object so the correct response headers get set):
var payload1 = JsonConvert.DeserializeObject(jsonPayload1);
return (ActionResult)new OkObjectResult(payload1);
From there, you should be good to go.
Note:
For convenience, the entirety of the "content" (and not "body") block is what you'd copy/paste into the adaptivecards.io designer. You might refactor the above to reflect that reality if it was important to you.
Could you please try this sample json { "$schema": "adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.2", "body": [ { "type": "Image", "url": "c.s-microsoft.com/en-us/CMSImages/…" }, { "type": "TextBlock", "text": "Sample image for Adaptive Card..", "wrap": true } ] }

Issue passing in custom parameters to Twilio API

I am attempting to build out a process that will do the following:
New contact lands in my CRM (Podio)
The CRM is triggered to send a POST containing a custom parameter to Twilio which will then initiate a flow
The Twilio flow will call my cell and prompt me to connect to the new contact
Once I press 1, it will take the custom parameter (new contact's phone number) and connect
me to them.
So far, I have been able to get 1-3 with no problem.
However, according to the the API documentation from Twilio I should be able to pass a 3rd parameter in the JSON body of my HTTP request containing custom "Parameters". When I attempt this the parameters aren't showing in the Twilio studio logs and thus I am unable to connect the call to the new lead.
This is the JSON body I am sending over to my Twilio Flow's API
{
"To": "+1xxxxxxxxx1",
"From": "+1xxxxxxxxx2",
"Parameters": {
"name": "example name",
"prospectphone": "+1xxxxxxxxx3"
}
}
When I view the logs in Twilio this is what I received.
{
"contact": {
"channel": {
"address": "+1xxxxxxxxx2"
}
},
"trigger": {
"request": {
"from": "+1xxxxxxxxx2",
"to": "+1xxxxxxxxx1",
"parameters": {}
}
},
"widgets": {},
"flow": {
"flow_sid": "FW936f72c0eb8d3945d0d55c62465e37a8",
"data": {},
"channel": {
"address": "+1xxxxxxxxx2"
},
"sid": "FN955cdb12827f84c8af8fc9b5264e5a28"
}
}
I really can't figure out what I'm missing here? Has anyone run into this before? Is this something you can only do if you're using the SDK or does the additional parameter need to be passed in some other way?
It should be sent x-www-form-urlencoded.
From the documentation:
"Note: the JSON value must explicitly be passed as a string, not as a hash object. Depending on your particular HTTP library, you may need to add quotes or URL encode the JSON string."
Trigger a Twilio Studio Flow Execution via the REST API

How can I post a complex character to SharePoint REST API?

Whenever I try a post a complex character to create a list entry in an O365 SharePoint list (via REST API) I get a JSON parse error from the server. The following is the simple post and it is the β (beta) character which causes the fail. &mdash (—) and other non-simple characters also cause the fail.
The code works just fine for alphabetic characters. It appears to me to be a parsing issue on the SharePoint side but I wanted to know if I was missing something stupid (it happens...)
If I remove the β character from Title field it works just fine. If I create the list item manually through the SP web interface it works just fine, so I know that it is not that the character is invalid, just the creation of the list item through the API.
The headers for the post are:
var outHeaders = {
"Content-Type": "application/json;odata=verbose",
"Accept": "application/json;odata=verbose",
"Authorization": 'Bearer ' + token,
"Content-Length": data.length,
"X-RequestDigest": digest,
"IF-MATCH" : "*"
}
The data being posted is as follows
{
"__metadata": {
"type": "SP.Data.EmailArchiveListItem"
},
"Title": "TEST fail email β",
"Sender": "Mark Roden",
"Recipient": "Mark Roden",
"Body": "HI Marky"
}
The error returned is:
400
Bad Request
{
"error": {
"code": "-1, Microsoft.SharePoint.Client.InvalidClientQueryException",
"message": {
"lang": "en-US",
"value": "Invalid JSON. Unexpected end of input was found in JSON content. Not all object and array scopes were closed."
}
}
}
Any input/thoughts appreciated.
Try using this code: β That should make it through.
In 2021 (five years later) I had a similar problem (using the SharePoint MS Graph REST API) which I fixed by specifying the charset in the content-type explicitly:
application/json; charset=utf-8
Joe Jorden's answer at least got me this far - If you post the β or — into an RTF Field it works - posting it into a plain text field does not.

"additional properties" error in Survey Monkey API call

I'm trying to use the create_flow endpoint to the Survey Monkey API. It is sending back a status 3 message with the following error:
additional properties not defined by 'properties' are not allowed in field '_data'
I'm able to do successfully use all other API endpoints and have a valid API key and durable OAuth token.
Here's an example JSON body that I'm sending to: https://api.surveymonkey.net/v2/batch/create_flow?api_key=apikeyhere
{
"survey": {
"template_id": "566",
"survey_title": "test1",
"collector": {
"type": "email",
"name": "collector1",
"recipients": [
{
"email": "email#example.com"
}
]
},
"email_message": {
"reply_email": "myemail#example.com",
"subject": "this is a test"
}
}
Note: JSON formatting here is being generated automatically using RJSONIO
Any ideas what might be causing the error? It seems like all fields are correctly named and where they're supposed to be, so I'm not sure what the problem is.
It's a bad error message unfortunately - it's a known issue. It means you are providing extra keys that are not part of the create_flow schema.
The issue here is that the "email_message" and "collector" keys have been nested inside of "survey", instead of being in the main JSON body like the "survey" key. Move them out a level and it should work.

Resources