Reading parts of the trigger body in Azure Logic App - servicebus

I have a logic app which is triggered by new messages on a Service Bus subscription. The message is a json object, like the following:
{
"PublisherName": "XXX",
"PublisherKey": "XXX",
"Identifier": "XXX",
"Value": {
// ...
}
}
How can I do an http request, using the publisher key as a header, the identifier as a query parameter, and the value as the body?

Typically, your service bus message from your subscription will be base64 encoded.
Try the following in code view:
"queries": {
"Identifier": "#json(base64ToString(triggerBody()?['ContentData'])).Identifier"
}
"headers": {
"PublisherKey": "#json(base64ToString(triggerBody()?['ContentData'])).PublisherKey"
}

Try the following
"httpAction": {
"type": "Http",
"inputs": {
"body": "#triggerBody().Value",
"method": "POST",
"uri": "http://endpoint.com",
"queries": {
"Identifier": "#triggerBody().Identifier"
}
"headers": {
"PublisherKey": "#triggerBody().PublisherKey"
}
}
}

Related

whatsapp api error during sending an created template

{ "messaging_product": "whatsapp",
"to": "91********5",
"type": "template",
"template": {
"name": "demo_template",
"language": {
"code": "en_US"
}
}
}
This is passed as a post method.
demo_template is an existing template created by me.
Getting error like this:
{
"error": {
"message": "(#132012) Parameter format does not match format in the created template",
"type": "OAuthException",
"code": 132012,
"error_data": {
"messaging_product": "whatsapp",
"details": "header: Format mismatch, expected IMAGE, received UNKNOWN"
},
"error_subcode": 2494073,
"fbtrace_id": "ARtWScjGa0rADjfHvbOH4bS"
}
}
For image you have to first upload the image in media library then you can get id for the media you have uploded then you can attach that id with the messaging template you send out in headers in your case it is image.check this link here
or you can directly use url link to attach media.{ "type": "header", "parameters": [ { "type": "image", "image": { "link": "https://URL" } } ] },
The parameter values included in the request are not using the format specified in the template. See the Message Template Guidelines.

Fetch data in a POST Request in asp.net core

I am using an external web link to get data and fetch it to json The reason why I need to handle it by the controller is to filter the data of it. Sadly, an api link was programmatically incorrect because instead of requesting it as GET method, it was programmed as POST method. I had this code simple code below but the return was a header data not the actual data of the api.
[HttpPost, Route("get/subproject")]
public ActionResult subproject()
{
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(#"https://thisisjustasample.com/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage hrm = client.PostAsync("/api/new/get/subproject/details/get_dto", null).Result;
return Ok(hrm);
}
}
The output of the code above is this.
{
"version": "1.1",
"content": {
"headers": [
{
"key": "Content-Length",
"value": [
"29942142"
]
},
{
"key": "Content-Type",
"value": [
"application/json; charset=utf-8"
]
},
{
"key": "Expires",
"value": [
"-1"
]
}
]
}
}
What I need is this data below.
{
"sub_project_id": 267892,
"engineeringMigrationId": 0,
"modality_id": 21,
"id": null,
"reportID": null,
"month": null,
"year": null,
"cycle_id": 204
}
Any help would be appreciated. Thanks in advance.
Don't return hrm directly, If you want to get the response data, you need return.
hrm.Content.ReadAsStringAsync().Result
Demo
1.return Ok(hrm);
2.return Ok(hrm.Content.ReadAsStringAsync().Result);

Agora cloud recording is not saving file in S3 when streaming from android

I have already viewed this question
I followed the procedure, first called acquire then start then stop
I followed the procedure , first called acquire then start then stop
Here is my acquire call
https://api.agora.io/v1/apps/{{APPID}}/cloud_recording/acquire
Request body
{
"cname": "{{AccessChannel}}",
"uid": "{{RecordingUID}}",
"clientRequest":{
}
}
The response
{
"resourceId": "nUwUbQf9Zg6tsgtLslGnDg0lk8RYaUE09pqOuSIgwfzZ8g-RNe4wP9vsFnBhU785sHbxN0_dI8MVBqLWrCy7TCUo4U3XXne-2hA7expaSg-NgpZ5PcnFK-IrNSvmFNJqL4PGS9hw2q7lDYEtJH_0VgBG4Qdsg2TofWuF2DW7IMAt8NYBp9Hh_06d1K3pIcMJFPUWvfV7fInPDrecYuDmZdiRS9AYydjQlHa6jb51S0sKXzTVYELCJZAXP-ALS_whAh_ojFeltKLKzOC9iYodyAAwq4QnclbL3LKvBeVtCEfS9WjyYzyHDhCngJ-JrIwW"
}
Then I call start
URL : https://api.agora.io/v1/apps/{{APPID}}/cloud_recording/resourceid/{{resourceId}}/mode/mix/start
Body:
{
"cname":"{{AccessChannel}}",
"uid":"{{RecordingUID}}",
"clientRequest":{
"recordingConfig":{
"maxIdleTime":300,
"streamTypes":2,
"channelType":1,
"videoStreamType":0,
"transcodingConfig":{
"height":640,
"width":360,
"bitrate":500,
"fps":15,
"mixedVideoLayout":1,
"backgroundColor":"#FF0000"
},
"subscribeVideoUids":[
"123",
"456"
],
"subscribeAudioUids":[
"123",
"456"
],
"subscribeUidGroup":0
},
"storageConfig":{
"vendor":1,
"region":0,
"bucket":"{{Bucket}}",
"accessKey":"{{AccessKey}}",
"secretKey":"{{SecretKey}}",
"fileNamePrefix":[
"directory1",
"directory2"
]
},
"recordingFileConfig":{
"avFileType":[
"hls"
]
}
}
}
Response
{
"resourceId": "nUwUbQf9Zg6tsgtLslGnDg0lk8RYaUE09pqOuSIgwfzZ8g-RNe4wP9vsFnBhU785sHbxN0_dI8MVBqLWrCy7TCUo4U3XXne-2hA7expaSg-NgpZ5PcnFK-IrNSvmFNJqL4PGS9hw2q7lDYEtJH_0VgBG4Qdsg2TofWuF2DW7IMAt8NYBp9Hh_06d1K3pIcMJFPUWvfV7fInPDrecYuDmZdiRS9AYydjQlHa6jb51S0sKXzTVYELCJZAXP-ALS_whAh_ojFeltKLKzOC9iYodyAAwq4QnclbL3LKvBeVtCEfS9WjyYzyHDhCngJ-JrIwW",
"sid": "6068aec4fd4fc47b623bceaf1f2c8f6b"
}
And finally I called stop
URL: https://api.agora.io/v1/apps/{{APPID}}/cloud_recording/resourceid/{{resourceId}}/sid/{{sid}}/mode/mix/stop
Body:
{
"cname": "{{AccessChannel}}",
"uid": "{{RecordingUID}}",
"clientRequest": {}
}
And the response is
{
"resourceId": "nUwUbQf9Zg6tsgtLslGnDg0lk8RYaUE09pqOuSIgwfzZ8g-RNe4wP9vsFnBhU785sHbxN0_dI8MVBqLWrCy7TCUo4U3XXne-2hA7expaSg-NgpZ5PcnFK-IrNSvmFNJqL4PGS9hw2q7lDYEtJH_0VgBG4Qdsg2TofWuF2DW7IMAt8NYBp9Hh_06d1K3pIcMJFPUWvfV7fInPDrecYuDmZdiRS9AYydjQlHa6jb51S0sKXzTVYELCJZAXP-ALS_whAh_ojFeltKLKzOC9iYodyAAwq4QnclbL3LKvBeVtCEfS9WjyYzyHDhCngJ-JrIwW",
"sid": "6068aec4fd4fc47b623bceaf1f2c8f6b",
"code": 435
}
I am not sure what did I do wrong ?
My streaming is running on a android device , only one broadcaster no audience
And I called the API from postman
I have double checked every parameter
Please make sure you are passing the authentication token in the request body of start API.
Here is sample
{
"cname":"{{AccessChannel}}",
"uid":"{{RecordingUID}}",
"clientRequest":{
"token": "<place token here>",
"recordingConfig":{
"maxIdleTime":300,
"streamTypes":2,
"channelType":1,
"videoStreamType":0,
"transcodingConfig":{
"height":640,
"width":360,
"bitrate":500,
"fps":15,
"mixedVideoLayout":1,
"backgroundColor":"#FF0000"
},
"subscribeVideoUids":[
"123",
"456"
],
"subscribeAudioUids":[
"123",
"456"
],
"subscribeUidGroup":0
},
"storageConfig":{
"vendor":1,
"region":0,
"bucket":"{{Bucket}}",
"accessKey":"{{AccessKey}}",
"secretKey":"{{SecretKey}}",
"fileNamePrefix":[
"directory1",
"directory2"
]
},
"recordingFileConfig":{
"avFileType":[
"hls"
]
}
}
}

Google API post request to IBM blockchain error

I am trying to send reqest from google api script to IBM Blockchain SaaS project Bluemix.
The code is:
var url = "https://24f7d912-60f4-4eaf-89c6-b3e34b2247f9_vp1-api.blockchain.ibm.com:443/chaincode";
var headers =
{"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID": {
"name": "c86de893fe7203e09add8c47237ffa377814311d9c3cb21ca4d3d5c4eeca65294d801a1f2e5a2d6b22b91096d9c8e42910046d2ab02d295ad0a0fb0b716e9a69"
},
"ctorMsg": {
"function": "query",
"args": ["b"]
},
"secureContext": "dashboarduser_type0_953add49d4"
},
"id": 1
};
var options =
{
"method" : "post",
"headers" : headers,
"MuteHttpExceptions":false
};
var response = UrlFetchApp.fetch(url,options);
var responseString=response.getContentText();
}
The error message is:
{"jsonrpc":"2.0","error":{"code":-32600,"message":"Invalid request","data":"Client must supply a payload for chaincode requests."},"id":null}
The request from Firefix Poster was answered correctly.
You have specified query as parameter to method and function but if you are trying to query using custom function ( Then specify method as query and function as custom function name that you have created in chaincode) as:
{"jsonrpc": "2.0",
"method": "query",
"params": {
"type": 1,
"chaincodeID": {
"name": "chainId"
},
"ctorMsg": {
"function": "customfunctionName",
"args": ["b"] //Argument to that custom function
},
"secureContext": "dashboarduser_type0_953add49d4"
},

How do you get all the email body parts? And how do you know how many parts exist?

I'm trying to read emails responded by the Gmail API.
I have trouble accessing all the "parts". And don't have great ways to traverse through the response. I'm also lost as to how many parts can exist so that I can make sure I read the different email responses properly. I've shortened the response below...
{ "payload": { "mimeType": "multipart/mixed", "filename": "",
], "body": { "size": 0 }, "parts": [ {
"body": {
"size": 0
},
"parts": [
{
"partId": "0.0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=\"us-ascii\""
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 2317,
"data": "RGVhciBNSVQgQ2x1YiBWb2x1bnRlZXJzIGluIEFzaWEsDQoNCkJ5IG5vdyBlYWNoIG9mIHlvdSBzaG91bGQgaGF2ZSByZWNlaXZlZCBpbnZpdGF0aW9ucyB0byB0aGUgcmVjZXB0aW9ucyBpbiBib3RoIFNpbmdhcG9yZSBhbmQgSG9uZyBLb25nIHdpdGggUHJlc2lkZW50IFJlaWYgb24gTm92ZW1iZXIgNyBhbmQgTm92ZW1iZXIg"
}
},
{
"partId": "0.1",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=\"us-ascii\""
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 9116,
"data": "PGh0bWwgeG1sbnM6dj0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTp2bWwiIHhtbG5zOm89InVybjpzY2hlbWFzLW1pY3Jvc29mdC1jb206b2ZmaWNlOm9mZmljZSIgeG1sbnM6dz0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTpvZmZpY2U6d29yZCIgeG1sbnM6bT0iaHR0cDovL3NjaGVtYXMubWljcm9zb2Z0LmNvbS9vZmZpY2UvMjA"
}
}
] }, {
"partId": "1",
"mimeType": "text/plain",
"filename": "",
"body": {
"size": 411,
"data": "X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18NClRoYW5rIHlvdSBmb3IgYWxsb3dpbmcgdXMgdG8gcmVhY2ggeW91IGJ5IGVtYWlsLCB0aGUgbW9zdCBpbW1lZGlhdGUgbWVhbnMgZm9yIHNoYXJpbmcgaW5mb3JtYXRpb24gd2l0aCBNSVQgYWx1bW5pLiANCklmIHlvdSB3b3VsZCBsaWtlIHRvIHVuc3Vic2NyaWJlIGZyb20gdGhpcyBtYWlsaW5nIGxpc3Qgc2VuZCBhIGJsYW5rIGVtYWlsIHRvIGxpc3RfdW5zdWJzY3JpYmVAYWx1bS5taXQuZWR1IGFuZCBwdXQgdGhlIGxpc3QgbmFtZSBpbiB0aGUgc3ViamVjdCBsaW5lLg0KRm9yIGV4YW1wbGU6DQpUbzogbGlzdF91bnN1YnNjcmliZUBhbHVtLm1pdC5lZHUNCkNjOg0KU3ViamVjdDogYXNpYW9mZg0K"
} } ] } }
Is there something I'm missing?
A MIME message is not just an array it's a full blown tree structure. So you'll have to traverse it to correctly handle it. Luckily JSON parsers are plentiful and the problem can easily be handled with recursion. In many languages there exist very useful email parsing libraries that can make accessing traditional parts (e.g. the text/plain or text/html displayable part, or attachments) not too laborious.
You'll have to set up walker functions to traverse through the json and pick out the bits you are after. Here is a part of what I wrote. This may help you jumpstart your code. NOTE: this is used inside of wordpress...hence the special jQuery call. Not needed if you do not need to use jquery inside wordpress.
function makeApiCall() {
gapi.client.load('gmail', 'v1', function() {
//console.log('inside call: '+myquery);
var request = gapi.client.gmail.users.messages.list({
'userId': 'me',
'q': myquery
});
request.execute(function(resp) {
jQuery(document).ready(function($) {
//console.log(resp);
//$('.ASAP-emailhouse').height(300);
$.each(resp.messages, function(index, value){
messageId = value.id;
var messagerequest = gapi.client.gmail.users.messages.get({
'userId': 'me',
'id': messageId
});//end var message request
messagerequest.execute(function(messageresp) {
//console.log(messageresp);
$.each(messageresp, responsewalker);
function responsewalker(key, response){
messagedeets={};
$.each(messageresp.payload.headers, headerwalker);
function headerwalker(headerkey, header){
if(header.name =='Date'){
d = new Date(header.value);
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();
var formatteddate = curr_month+'/'+curr_date+'/'+curr_year;
messagedeets['date']=formatteddate;
//$('.ASAP-emailhouse').append('<p>'+header.value+'</p>');
}
if(header.name =='Subject'){
//console.log(header.value);
messagedeets.subject=header.value;
}
}
messagedeets.body = {};
$.each(messageresp.payload.parts, walker);
function walker(partskey, value) {
//console.log(value.body);
if (value.body.data !== "undefined") {
//console.log(value.body);
var messagebody = atob(value.body.data);
messagedeets.body.partskey = messagebody;
}
console.log(messagedeets);
$('.ASAP-emailhouse').append('<div class="messagedeets"><p class="message-date">'+messagedeets.date+': <span class="message-subject">'+messagedeets.subject+'</span></p><p>'+messagedeets.body.partskey+'</p></div>');
}//end responsewalker
//$('.ASAP-emailhouse').append('</li>');
}
//$('.ASAP-emailhouse').append('</ul>');
});//end message request
});//end each message id
});//end jquery wrapper for wordpress
});//end request execute list messages
});//end gapi client load gmail
}
The MIME parts you are looking for are in an array. JSON does not tell you up front how many items are in an array. Even MIME itself does not provide a way of knowing how many parts are present without looking at the entire message. You will just have to traverse the entire array to know how many parts are in it, and process each part as you encounter it.
To know how much parts exists, you can just use the Length property.
Example :
json.payload.parts.length
For your example, this property is 2 because there are 2 parts.