Http call to the graph and asynchronous pattern does not seems to work - power-automate

I'm triggering an HTTP call from a power automate workflow to the MS Graph.
The operation is a long operation (cloning a MS teams), and return HTTP 202, with the Location header.
The HTTP action has the Asynchronous Pattern option set to yes.
I'm expecting Power Automate to automatically handle the wait for long operation to be finished.
However, the http action returns the 202 code, and I have to do myself the plumbing (do until sleep pattern).
How to properly call MS graph long operation and properly wait for completion ?
FYI, here's a sample request I make:
Method : POST
URL : https://graph.microsoft.com/v1.0/teams/b78b07c8-9af3-4af9-b995-315c6b674da8/clone
Body :
{
"displayName": "Some new team",
"mailNickname": "somenewteam",
"partsToClone": "apps,tabs,settings,channels,members",
"visibility": "private"
}
Headers :
{
"ContentType": "application/json"
}
Plus all authentication headers (handled by the http action itself):
{
"authority": "https://login.microsoftonline.com",
"tenant": "some guid",
"audience": "https://graph.microsoft.com",
"clientId": "some guid",
"secret": "*sanitized*",
"type": "ActiveDirectoryOAuth"
}
In comparison, using the option to call other long workflows (with http trigger and final "http response" action) works as expected

Related

How to debug JMeter the error JsonToken EndArray is not valid

Before hand will be some images as I don't know how to explain them better.
I have an HTTP Request POST that has the parameters below:
{"ShiftId":${Param_S02_ShiftId},"Date":null,"StartTime":"${Param_S02_Pick_Date}T00:00:00.000Z","EndTime":"${Param_S02_Pick_Date}T23:00:00.000Z","RouteTemplateId":${Param_S02_RouteTemplateId},"VehicleId":${Param_S02_VehicleId},"SelectedEmployees":[{"RouteTemplateRoleId":${Param_S02_RoleId_1_driver},"EmployeeId":${Param_S02_1_driver}},{"RouteTemplateRoleId":${Param_S02_RoleId_2_driver},"EmployeeId":${Param_S02_2_driver}],"TeamBoardId":${Param_S02_Teamboard}}
As you can see this is the same API sent by the browser
The problem is that I am getting this error message that I could not find the solution aroud.
{"message": "JsonToken EndArray is not valid for closing JsonType Object. Path 'SelectedEmployees1', line 1, position 237.","type":"Newtonsoft.Json.JsonReaderException","stackTrace":" at Newtonsoft.Json.JsonReader.ValidateEnd(JsonToken endToken)\r\n at Newtonsoft.Json.JsonTextReader.ParsePostValue(Boolean ignoreComments)\r\n at Newtonsoft.Json.JsonTextReader.Read()\r\n at Newtonsoft.Json.Linq.JContainer.ReadContentFrom(JsonReader r, JsonLoadSettings settings)\r\n at Newtonsoft.Json.Linq.JContainer.ReadTokenFrom(JsonReader reader, JsonLoadSettings options)\r\n at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings)\r\n at ApiService.EntityObjectServiceController2.ParseSaveRequestAsync() in C:\\a\\1\\s\\API\\src\\Framework\\ApiService\\EntityObjectServiceController.NETStandard.cs:line 151\r\n at ApiService.EntityObjectServiceController2.Create() in C:\a\1\s\API\src\Framework\ApiService\EntityObjectServiceController.NETStandard.cs:line 123\r\n at lambda_method3708(Closure , Object )\r\n at g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)"}
Do I need to add something in the Header?
Maybe is something with this part of the call where I have 0 and 1
You're sending an invalid JSON, your SelectedEmployees array is missing closing bracked ], my expectation is that you need to amend your payload to something like:
{
"ShiftId": ${Param_S02_ShiftId},
"Date": null,
"StartTime": "${Param_S02_Pick_Date}T00:00:00.000Z",
"EndTime": "${Param_S02_Pick_Date}T23:00:00.000Z",
"RouteTemplateId": ${Param_S02_RouteTemplateId},
"VehicleId": ${Param_S02_VehicleId},
"SelectedEmployees": [
{
"RouteTemplateRoleId": ${Param_S02_RoleId_1_driver},
"EmployeeId": ${Param_S02_1_driver}
},
{
"RouteTemplateRoleId": ${Param_S02_RoleId_2_driver},
"EmployeeId": ${Param_S02_2_driver}
}
],
"TeamBoardId": ${Param_S02_Teamboard}
}
once you start sending syntactically correct JSON at least this error will go away, you can test it against i.e. online JSON validator
Going forward given you're capable of successfully execute the request using your browser you can just record it using JMeter's HTTP(S) Test Script Recorder or JMeter Chrome Extension

Are batch json-rpc requests not supported with near?

When trying to batch json rpc requests like this:
[
{
"jsonrpc":"2.0",
"id":"46500000",
"method":"block",
"params":{
"block_id": 46500000
}
},
{
"jsonrpc":"2.0",
"id":"46500001",
"method":"block",
"params":{
"block_id": 46500001
}
}
]
The response given is this:
{
"jsonrpc": "2.0",
"error": {
"name": "REQUEST_VALIDATION_ERROR",
"cause": {
"name": "PARSE_ERROR",
"info": {
"error_message": "JSON RPC Request format was expected"
}
},
"code": -32700,
"message": "Parse error",
"data": "JSON RPC Request format was expected"
},
"id": null
}
This is quite confusing since the above request is a valid jsonrpc request according to the spec. Are batch requests not supported on near?
You are right, batch JSON RPC requests are not supported by nearcore JSON RPC implementation. Batch JSON RPC requests can become arbitrary heavy. It is preferred to leverage load balancer to get several requests resolved, so just make separate calls instead of batching them.
I wonder what is your use-case, though. Maybe you want to take a look into Indexer Framework

Azure Logic App throwing 302 Redirect Error having Server=BIG IP in Response Header for HTTP

I am getting Redirect 302 error for HTTP Request in Logic App. I am calling OneIdentityServer to get access token. Then I am calling Rest API passing access token as Header for key Authorization. I am getting 302 Redirect error in response with headers information like Server = BIG IP, Location= /my.policy
The same above request when triggered through Postman or SOAPUI is working fine, I am getting successful response. But the same is failing in Azure Logic App.
I have also implemented the above scenario in function app as well. It is working file when I run the function app code from visual studio using Postman. But when I test the same function app after publishing it to Azure portal, it is giving same error.
It seems like I have the same issue as you. I found one-way that did not work for me but maybe you could give it a shot if it fits your needs?
The solution that I found in a blogpost was first to add the action "Switch" to the logic app flow and then configure Switch to run after the HTTP is both successful and has failed.
Secondly, the Switch action should trigger on the output of the statuscode from the HTTP request.
If the statuscode equals 302 you should make another HTTP request but with URI being the output of the location header from the first HTTP request. This made my logic app result in statuscode 200 but the response for my logic app was that I needed to login to get access to the API.
But maybe it could be worth giving this solution a shot for your logic app?
Here's the link of the blogpost if you need deeper instructions: http://www.alessandromoura.com.br/2018/11/21/dealing-with-http-302-in-logic-apps/
Do you still have issues with this? Here is a screenshot of my http action: HTTP Action that is working.
I have put my URL in an variable since it changing for each pagination. I also found out that to use the authentication token from the first HTTP request I needed to parse the body to be able to access the token, here is the schema I used to parse the HTTP body from the request where you get access token:
{
"properties": {
"access_token": {
"type": "string"
},
"expires_in": {
"type": "string"
},
"expires_on": {
"type": "string"
},
"ext_expires_in": {
"type": "string"
},
"not_before": {
"type": "string"
},
"resource": {
"type": "string"
},
"token_type": {
"type": "string"
}
},
"type": "object"
}

Google Speech API: the requested URL was not found on this server

I am attempting some simple tests on the Google Speech API, and when my server makes a request to this url (below), I get the 404. that's an error response. Not sure why.
https://speech.googleapis.com/v1/speech:recognize?key=[MY_API_KEY]
The body of my request looks like this:
{
"config": {
"languageCode": "en-US",
"encoding": "LINEAR16",
"sampleRateHertz": 16000,
"enableWordTimeOffsets": true,
"speechContexts": [{
"phrases": ["Some", "Helpful", "Phrases"]
}]
},
"audio":{
"uri":"gs://mydomain.com/my_file.mp3"
}
}
And here is the response:
As you can see, that is a valid resource path, unless I'm totally mistaken about something (I'm sure I am): https://cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/recognize
Update 1:, Whenever I try this with the Google API explorer tool, I get this quota exceeded message (even though I have not yet issued a successful request to the API).
{
"error": {
"code": 429,
"message": "Quota exceeded for quota metric 'speech.googleapis.com/default_requests' and limit 'DefaultRequestsPerMinutePerProject' of service 'speech.googleapis.com' for consumer '[MY_API_KEY]'.",
"status": "RESOURCE_EXHAUSTED",
"details": [
{
"#type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Google developer console API key",
"url": "https://console.developers.google.com/project/[my_project_id]/apiui/credential"
}
]
}
]
}
}
Update 2: Interestingly, I was able to get some 200 ok's using the Restlet client, but even in those cases, the response body is empty (see screenshot below)
I have made a test by using the exact URL and Body content you added to the post, however, I was able to execute the API call correctly.
I noticed that if I add some extra character to the URL, it fails with the same 400 error since it doesn't exist. I would suggest you to verify that the URL of your request doesn't contain a typo and that the client you use is executing the API call correctly. Also, ensure that your calling code is not encoding the url, which could cause issues given the colon : that appears in the url.
I recommend you to perform this test by using the Try this API tool directly or Restlet client which are the ones that I used to replicate this scenario.

Send message from Postman to Microsoft Bot

I am trying to send a message to a bot I created and published to azure services so that the bot can then start messaging some of its users.
I am trying to make the requests on Postman first so that then I can build a controller for that interaction.
I am doing the following request:
POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded
Body:
grant_type:client_credentials
client_id: my_ms_app_id
client_secret: my_ms_app_secret
scope: https://api.botframework.com/.default
from this I get in the response the Bearer Authorization:
{
"token_type": "Bearer",
"expires_in": 3599,
"ext_expires_in": 0,
"access_token": "eyJ0eXA..."
}
Then I proceed with the following request:
POST https://skype.botframework.com/v3/conversations
Content-Type: application/json
Authorization: Bearer eyJ0eXAi....
{
"bot": {
"id": "i don't have this id so i pass some string",
"name": "connector controller"
},
"isGroup": false,
"members": [
{
"id": "28:...", //ID of the bot I want to send the message to
"name": "Sp Bot"//Name of the bot I want to talk to
},
{
"id": "i don't have this id so i pass some string",
"name": "connector controller"
}
],
"topicName": "News Alert"
}
in response i get the conversation id which matches "id": "i don't have this id so i pass some string":
{
"id": "i don't have this id so i pass some string"
}
Then I proceed with the following POST request:
POST. https://skype.botframework.com/v3/conversations/i don't have this id so i pass some string/activities
Authorization: Bearer eyJ0...
Content-Type:application/json
I get the following response:
400 Bad Request
{
"error": {
"code": "ServiceError",
"message": "The conversationId 29... and bot .... doesn't match a known conversation"
}
}
It looks like the problem occurs between the second and the 3 post method. It looks like that the https://skype.botframework.com/v3/conversations does not generate a conversation with the bot with Id I entered.
So when I make the final call to the bot: https://skype.botframework.com/v3/conversations/.../activities I always get the serviceError message.
Based on your comments you are trying to create a custom "channel/client" to talk with the bot.
For doing that, I would recommend taking a look to Direct Line which seems the way to go for achieving your requirement.
I'm not sure which language are you using, so I will send you pointers to both C# and Node.
These are samples that will show you how to create custom client using Direct Line to interact with your bot:
C#
Basic Direct Line sample
Direct Line sample using Web Sockets
Node.js
Basic Direct Line sample
Direct Line sample using Web Sockets
All the samples are using a console app as the "custom channel".
Since you're going to make an app talk to your bot and most likely be using DirectLine after you and Ezequiel chatted, I created a series of screencaps on connecting to the DirectLine endpoint through Potsman. I'm going to assume that you know how to use environmental and global variables in Postman, here are Postman's documentation for other people's benefit. Also, the DirectLine v3.0 docs are here.
Below is a capture of the directline endpoint you would request a token from, {{DLsecret}}'s guts looks like this, Bearer <your-dl-secret>:
Here is an example of the response body you would receive on a valid call:
You may have noticed that I have some test results, in the screenshow below it has five (vs four) tests because I added the test verifying that the conversationId was set in the environment variables:
Here's the second query sent, which contains an actual message:
This is the request body which has the message:
And here is the response body:

Resources