Why can't send queue message text to an Azure Function? - azure

I have an Azure Logic App with a queue trigger. The queue message is JSON. When I send "Message text" to an Azure function, I get
UnsupportedMediaType
{
"Message": "The WebHook request must contain an entity body formatted as JSON."
}
I'd assumed this would work directly.I tried setting request body to
#{json(<Message text>)}
where is the select dynamic content item, but I get red message "Enter a valid json".
What's the trick to making this connection? Do I have to pass in and then parse out "Message text" in my function? Again, I assumed it would do that automagically.

The #{} syntax indicates string interpolation. This means that your expression #{json(<Message text>)} de-serializes the message text to json, and then serializes it again.
Hence the expression that you want to use is
#json(<Message text>)

For future readers.
I was passing some (what seems to be to be valid) json to my webhook.
And kept getting the
"Message": "The WebHook request must contain an entity body formatted as JSON."
error.
:(
Finally, I found a json "expression" that did its voodoo and got rid of the error. I argument from the json-expression was my previous action's output, which was valid json. It apparently needs just a little help!
The raw (non designer) code was:
"GenericWebHookCsharpOne": {
"type": "Function",
"inputs": {
"body": "#json( body('MyPreviousAppLogicActionWhichIsAnAzureFunction'))",
"method": "POST",
"function": {
"id": "/xxxxxxxxxxxxxxxxxxxxxxxx
}

Related

Time series insight API returning Could not cast or convert from System.String to Microsoft.Rdx.Client.Events.Property

Hi we have just started using time series insight .We need to list specified list of values of properties under particular Time series id .As per the documentation in azure we were using the following API in post method to achieve this .
https://XXXXX_EnvironmentFqdn_XXXXX.env.timeseries.azure.com/timeseries/query?api-version=2018-11-01-preview
When posting the following request body to the API
{
"getEvents":{
"timeSeriesId": ["UniqueId"],
"searchSpan": {
"from": "2019-02-17T00:00:00Z",
"to": "2019-02-18T00:16:50Z"
},
"projectedProperties": ["DesiredProp"]
}
}
it returns a 400 Bad Request with following error message.
{
"error": {
"code": "InvalidInput",
"message": "Error converting value \"DesiredProp\" to type
'Microsoft.Rdx.Client.Events.Property'. Path
'getEvents.projectedProperties[0]', line 9, position 45.\r\n---> Could
not cast or convert from System.String to
Microsoft.Rdx.Client.Events.Property.\r\n"
}
}
on removing the projectedProperties property from response body API works fine,but it will return all the properties of the time series .
any help will me much appreciated and thanks in advance .

Web push messaging.setBackgroundMessageHandler not working

I implemented web-push notifications on my site with Google Firebase service.
firebase.google.com/docs/cloud-messaging/js/client
I tested it and everything works fine, but when my website window isn't in focus (it's in background) or closed and if I get push-notification it will disappear after 20 seconds.
In my https://hdlava.me/j/firebase_subscribe.js file I added
requireInteraction: true
flag in messaging.onMessage so if I get push mesage when my website is open the message won't disappear until I click on it.
I tried to add this
requireInteraction: true
in messaging.setBackgroundMessageHandler in my https://hdlava.me/firebase-messaging-sw.js, but it's not working. Even:
console.log('[firebase-messaging-sw.js] Received background message ', payload)
doesn't work. It looks like whole messaging.setBackgroundMessageHandler does not work.
Can someone please help me figure out what is the problem ? Also if I use in firebase-messaging-sw.js
self.addEventListener("push",function(event)
instead messaging.setBackgroundMessageHandler so I have two messges at once. First message disappears and second one doesn't, but second one is not clickable. Is it possible to prevent first message and make second one to be clickable ?
Referring to the FCM docs:
https://firebase.google.com/docs/cloud-messaging/js/receive
"Note: If you set notification fields in your HTTP or XMPP send request, those values take precedence over any values specified in the service worker."
So, if you have
{
"notification": {
"title": "Your title",
"body": "Your message"
},
"to": "topic",
}
It never triggers the BackgroundMessageHandler. Because sending data this way, simply overrides your variables. If you want to trigger it you need to send your notification like this:
{
"data": {
"notification": {
"title": "Your title",
"body": "Your message"
}
},
"to": "topic",
}

Can Cloudant list/show functions return objects and arrays(any JSON)?

As per the API documentation for Cloudant: Show function can be used to render a document in a different format or extract only some information from a larger document. Same is the case for a list function, the only difference is that it applies on a set of documents. I created a design document with a show function as follows:
{ "shows": { "showDemo":"function(doc,req){return {'body': doc, 'headers':{'Content-Type':'application/json'}}}" } }
When I use this function, _design/showFunc/_show/showDemo/doc1, I get the following error:
{ "error": "unknown_error", "reason": "badarg", "ref": 1793182837 }
I have observed the same error when the show function returns an array. However, no error is given when HTML,Text, XML is returned. Can we say that list/show functions can only return data in a format other than JSON? This example shows the "Accept" header for req object request Object.
What's happening here is that the show function needs to return a response object. From the docs (see http://docs.couchdb.org/en/2.1.0/json-structure.html#response-object) the body field needs to be a string, so you can return whatever you like but it needs to be stringified or otherwise turned into a format that can be sent as HTTP.
If you want to send JSON then doing JSON.Stringify(doc) as the value for body should do what you expect.

Azure Rest API " Resource not found for the segment 'messages?$filter=From'. "

I am trying to access messages for a specific folder which used to work. For some reason passing "?" in the url is rejected as "illegal character" in our api so I I have encoded the "?" to "%3F" and the final url looks like this:
https://graph.microsoft.com/v1.0/me/MailFolders/INBOX/messages?$filter=From/EmailAddress/Address eq 'alerts-noreply#mail.windowsazure.com'
The header contains the following.
("Authorization", "Bearer " + token)
("Content-Type", "application/json")
("Accept", "application/json")
("grant_type", "client_credentials")
I am using v1 of the Azure REST API as you can see. I can't understand what's happening.
Error I received.
{
"error": {
"code": "BadRequest",
"message": "Resource not found for the segment 'messages?$filter=From'.",
"innerError": {
"request-id": "d2e9b359-d40d-4c0a-a0a5-b4e3cf4b5ecd",
"date": "2017-03-24T14:35:28"
}
}
}
I appericiate your help.
You can't encode the ? as %3F, that breaks it. By encoding it that way, you're indicating that it's not the query parameter separator, so the server is trying to find a segment called messages?$filter=From :).
I think the issue here is capitalization issues.
If you look at the query you have copied above, you have capitalized:
https://graph.microsoft.com/v1.0/me/MailFolders/INBOX/messages?$filter=From/EmailAddress/Address eq 'alerts-noreply#mail.windowsazure.com'
When these 3 letters need to all be lowercase (sample below from our documents):
GET https://graph.microsoft.com/v1.0/me/messages?$filter=from/emailAddress/address eq 'jon#contoso.com'

Odata $filter for the date in the Office 365 REST API

I'm trying to retrieve events for a user from its Office 365 account using the REST API but filtered by the field "Start". For instance, retrieve all the events that will happen after the date: 2014-08-29T09:13:28' but i'm always retrieving this error message
{
"error": {
"code": "ErrorInvalidUrlQuery",
"message": "The query parameter '$filter' is invalid.",
"innererror": {
"message": "The query parameter '$filter' is invalid.",
"type": "Microsoft.Exchange.Services.OData.InvalidUrlQueryException",
"stacktrace": " at Microsoft.Exchange.Services.OData.Web.ODataQueryOptions.Populate()
at Microsoft.Exchange.Services.OData.ODataContext..ctor(HttpContext httpContext, Uri requestUri, ServiceModel serviceModel, ODataPathWrapper odataPath, ODataUriParser odataUriParser)
at Microsoft.Exchange.Services.OData.Web.RequestBroker.InitializeODataContext()
at Microsoft.Exchange.Services.OData.Web.RequestBroker.Process()",
"internalexception": {
"message": "A binary operator with incompatible types was detected. Found operand types 'Edm.DateTimeOffset' and 'Edm.Int32' for operator kind 'Equal'.",
"type": "Microsoft.OData.Core.ODataException",
"stacktrace": " at Microsoft.OData.Core.UriParser.Parsers.BinaryOperatorBinder.PromoteOperandTypes(BinaryOperatorKind binaryOperatorKind, SingleValueNode& left, SingleValueNode& right)
at Microsoft.OData.Core.UriParser.Parsers.BinaryOperatorBinder.BindBinaryOperator(BinaryOperatorToken binaryOperatorToken)
at Microsoft.OData.Core.UriParser.Parsers.MetadataBinder.Bind(QueryToken token)
at Microsoft.OData.Core.UriParser.Parsers.FilterBinder.BindFilter(QueryToken filter)
at Microsoft.OData.Core.UriParser.ODataUriParser.ParseFilterImplementation(String filter, IEdmType elementType, IEdmNavigationSource navigationSource)
at Microsoft.OData.Core.UriParser.ODataUriParser.ParseFilter()
at Microsoft.Exchange.Services.OData.Web.ODataQueryOptions.Populate()"
}
}
}
}
Here all the thing i've tried:
[ressource]=https://outlook.office365.com/
url: [ressource]EWS/OData/Me/Events?$filter=Start%20eq%20DateTime'2012-05-29T09:13:28'
url: [ressource]EWS/OData/Me/Events?$filter=Start%20eq%20DateTime'20141231'
url: [ressource]EWS/OData/Me/Events?$filter=month(Start)%20eq%2012
And i've tried the $filter on string field or the $select on the field Start and it worked perfectly so i think my error is caused by the date format but i don't know how to solve it, so if anybody could help me on that, it woud be great!
Thank you!
Filtering on dates does work, but you can't do everything in the OData v4 spec. For example, these all work for me:
/Me/Events?$filter=Start eq 2014-08-28T21:00:00Z
/Me/Events?$filter=Start ge 2014-08-28T21:00:00Z
Adding the "DateTime" in front of it makes it fail. The same with the month function. If you stick with the format above it should work for you.
In V2 of the O365 REST API you should use:
URL encoded: $filter=Start/DateTime%20ge%20%272017-03-15T00:00:00Z%27
Not URL encoded: $filter=Start/DateTime ge '2017-03-15T00:00:00Z'
More info https://msdn.microsoft.com/en-us/office/office365/api/complex-types-for-mail-contacts-calendar#filter-requests
Hi Just increase top=100 or more whatever you want to pull from your inbox.
https://outlook.office365.com/api/v2.0/me/MailFolders/Inbox/messages/?%24select=CreatedDateTime%2cLastModifiedDateTime%2cChangeKey%2cCategories%2cReceivedDateTime%2cSentDateTime%2cHasAttachments%2cSubject%2cBody%2cImportance%2cParentFolderId%2cSender%2cFrom%2cToRecipients%2cCcRecipients%2cBccRecipients%2cReplyTo%2cConversationId%2cIsDeliveryReceiptRequested%2cIsReadReceiptRequested%2cIsRead%2cIsDraft%2cWebLink&%24top=100&%24skip=0"

Resources