Sending email with Azure logic app after triggering via httpRequest - c#

I've a azure logic app which contains two operations.
When a httpRequest is received.
Send email (v2)
I'm trying to send an email with the content of "task" when triggered by the httpRequest.
HttpRequest body json schema:
"properties": {
"due": {
"type": "string"
},
"email": {
"type": "string"
},
"task": {
"type": "string"
}
},
"type": "object"
}
I've added the "task" object from the dynamic content in the body of the email. I want the body of the email to contain the content of the "task" sent in the httpRequest.
Below is how I'm sending the httpRequest with the required json data. However, the email is always empty with no body. I must be doing something wrong. Any pointers would be appreciated.
await client.PostAsync(
logicAppUrl, new StringContent(jsonData, Encoding.UTF8, "application/json"));
jsonData content:
{"email":"test#gmail.com","due":"4/1/2020","task":"content1-------------"}

You can debug with Postman what your json should look like. It seems that you 1) either forgot to include the curly braces in your string or 2) forgot to escape your double quotes in the string. It should look like
string jsondata = "{ \"email\": \"test#gmail.com\", \"due\": \"4/1/2020\", \"task\": \"content1-------------\"}"
EDIT:
If the json doesn't match, go to the logic app's HTTP task, click Use sample payload to generate schema and copy your json into it. In your case, it should be
{
"type": "object",
"properties": {
"email": {
"type": "string"
},
"due": {
"type": "string"
},
"task": {
"type": "string"
}
}
}

Related

C# Firestore API POST - Cannot find field

I have hit a bit of a brick wall here. I am working in client side c# code and using the firestore API. I cannot post a document (with data) in. I am able to create a document by removing the line ".AddJsonBody(testdata)" below.
CODE
string url = "https://firestore.googleapis.com/v1/projects/<MYPROJECT>/databases/(default)/documents/Users";
var client = new RestClient(url);
string testdata = "{\"foo\":\"bar\"}";
var request = new RestRequest()
.AddJsonBody(testdata);
var response = await client.ExecutePostAsync(request);
ERROR
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name "foo" at 'document': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"#type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document",
"description": "Invalid JSON payload received. Unknown name "foo" at 'document': Cannot find field."
}
]
}
]
}
}
I have tried using document:commit. I have tried various different methods of parsing the data, all keep getting similar errors.

Parsing JSON Using Newtonsoft.Json Without Knowing the Structure

I'm working on a project that involves automating API calls using a Swagger Definition. I download the swagger.json file. The structure of the JSON Object I need to parse is not consistent. When parsing paths, there are a list of objects, then within that they have the methods that can be used for that specific path. I can retrieve just the path using various string methods but my question was, is there a good way to parse json if the JSON is structured in such a way that it does not have a firm key? Here is an example of what I mean:
{"/user": {
"post": {
"tags": [
"user"
],
"summary": "Create user",
"description": "This can only be done by the logged in user.",
"operationId": "createUser",
"consumes": [
"application/json"
],
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"in": "body",
"name": "body",
"description": "Created user object",
"required": true,
"schema": {
"$ref": "#/definitions/User"
}
}
],
"responses": {
"default": {
"description": "successful operation"
}
}
}
}
If I wanted to just parse that path and retrieve the method object how could I go about that considering sometimes the object will be "post" or sometimes it will be "get", "put", etc depending on what is allowable for the path.
JObject jsonResp = swaggerDownload();
JObject paths = (JObject)jsonResp["paths"];
foreach (var i in paths)
{
string pathToString = i.ToString();
var shaveSomethings = pathToString.Substring(1, something.Length - 2);
var pathAndJson = shaveSomethings.Split(new[] { ',' }, 2);
string correctJsonStructure = "{\"" + pathAndJson[0] + "\":" + pathAndJson[1] + "}";
JObject bd = JObject.Parse(correctJsonStructure);
//dynamic pathsTest = JsonConvert.DeserializeObject<dynamic>(correctJsonStructure);
//JObject result = JsonConvert.DeserializeObject<JObject>(correctJsonStructure);
//Console.WriteLine(bd["/user"]);
}
The swagger.json file should have full definition of each entity that endpoints return. You can follow How to create Rest API client to get a working client.
I've dealt with an API where responses didn't always match the definition. I saved all responses to a store/log first and then would try to de-serialize JSON. In case of an exception I would go back to store/log and see what was different and update my code to accommodate for the change. After few iterations there were no new changes and the ordeal was over.
Hope that helps.

Kustomer API, how to add attachment in Conversation

I am using Kustomer API, I have successfully created the attachment, but I am not able to add the attachment in the Conversation. I'm not able to find any API documentation about how to add in the conversation.
https://apidocs.kustomer.com/?version=latest
Can you guys please help me?
Thanks.
When you create a message with the Kustomer API you would include the attachment ID of the attachment you created in the attachments array on the message object.
You need to send a Patch request to the message you want to add this attachment to. Attachments are added to messages, not Conversations.
The attachment you created would look something like this:
"data": {
"id": "5ec42bbad47d84001a0dd107",
"type": "attachment",
"attributes": {
"name": "testing.png",
"contentType": "image/png",
"contentLength": 1282,
"redacted": false,
"uploaded": false,
"createdAt": "2020-05-19T18:55:54.390Z",
"updatedAt": "2020-05-19T18:55:54.390Z",
"context": "attachment"
},
"relationships": {
"org": {
"data": {
"id": "5e664db1c9639a0019c67fd0",
"type": "org"
},
"links": {
"self": "/v1/orgs/5e664db1c9639a0019c67fd0"
}
}
},
"links": {
"self": "/v1/attachments/5ec42bbad47d84001a0dd107"
}
},
"meta": {
"provider": "s3",
"upload": {
"url": "https://s3.amazonaws.com/kustomer-prod1-attachments",
"fields": {
"key": "attachments/5e664db1c9639a0019c67fd0/5ec42bbad47d84001a0dd107-testing.png",
"acl": "private",
"Content-Type": "image/png",
"X-Amz-Meta-Attachment-Id": "5ec42bbad47d84001a0dd107",
"bucket": "kustomer-prod1-attachments",
"X-Amz-Algorithm": "AWS4-HMAC-SHA256",
"X-Amz-Credential": "AKIAIIKHW25JWTRL7R7Q/20200519/us-east-1/s3/aws4_request",
"X-Amz-Date": "20200519T185554Z",
"Policy": "eyJleHBpcmF0aW9uIjoiMjAyMC0wNS0xOVQxOToyNTo1NFoiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsMTI4MiwxMjgyXSx7ImtleSI6ImF0dGFjaG1lbnRzLzVlNjY0ZGIxYzk2MzlhMDAxOWM2N2ZkMC81ZWM0MmJiYWQ0N2Q4NDAwMWEwZGQxMDctdGVzdGluZy5wbmcifSx7ImFjbCI6InByaXZhdGUifSx7IkNvbnRlbnQtVHlwZSI6ImltYWdlL3BuZyJ9LHsiWC1BbXotTWV0YS1BdHRhY2htZW50LUlkIjoiNWVjNDJiYmFkNDdkODQwMDFhMGRkMTA3In0seyJidWNrZXQiOiJrdXN0b21lci1wcm9kMS1hdHRhY2htZW50cyJ9LHsiWC1BbXotQWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsiWC1BbXotQ3JlZGVudGlhbCI6IkFLSUFJSUtIVzI1SldUUkw3UjdRLzIwMjAwNTE5L3VzLWVhc3QtMS9zMy9hd3M0X3JlcXVlc3QifSx7IlgtQW16LURhdGUiOiIyMDIwMDUxOVQxODU1NTRaIn1dfQ==",
"X-Amz-Signature": "f00ce41d04f3c962f68ac6f4f096b8054cb81183ab9dbc0e5dd795d12e0239dc"
}
}
}
You would need send another POST request to the meta.upload.url you found in your response form the attachment you created. Per the API documents this will need to include all of the meta.upload.fileds information in this POST request. Once you did that the attachement would have been uploaded. To add this to a message you would need to send a PATCH request to the message API end point.
https://api.kustomerapp.com/v1/messages/:id
https://apidocs.kustomer.com/?version=latest#959920e4-17ff-458d-af90-5458297f2148
You would add your attachment id in the attachments object on the message object.
"attachments": {
"links": {
"self": "/v1/messages/5ec15c3fb2f51f0019ebee09/attachments"
},
"data": [
{
"type": "attachment",
"id": "5ec15c71d120a7001ad1c14b"
}
]
}
I wanted to make an update here: The payload of the Patch request to the message would look like this:
{
"attachments":[
{
"_id": "5ec15c71d120a7001ad1c14b",
"name": "Yass.png",
"contentType": "image/png",
"contentLength": 11288
}
]
}
This would be for adding an attachment to an existing message. If you want to add an attachment to a message that has not yet been sent you would have to create a draft message and send a POST request to add the attachment to that draft. /v1/drafts/{id}/attachments
There would be two things you need to do here
pass a sourceId in the body that is the ID of the original attachment
I think in the request URL include a query param that says ?method=post
If you have further questions please reach out to the support#kustomer.com email and we would be happy to assist you.

Google action doesn't provide user.profile.payload object after successful account linking

I followed this guide in order to create account linking in my app
https://developers.google.com/actions/identity/google-sign-in#json
I'm able to verify the user's jwt decoder and send back a response that the user is authorised. Then, according to the guide, in the next request, I should get the user's profile payload (user.profile.payload in the json structure) but It's missing from the next request. More than that, I get the tokenId for jwt verification again.
I think that what i miss here is in the possibleIntent object but I'm not sure, as I didn't see any documentation for that, because I work with asp.net server. There are SDKs with documentation for java and nodeJS only
this is the request provided for the sign in the contain the tokenId
{
"user": {
"locale": "en-US",
"lastSeen": "2019-07-11T14:18:10Z",
"idToken": "<tokenId>",
"userVerificationStatus": "VERIFIED"
},
"conversation": {
"conversationId": "ABwppHH9uZfcKj6pS6A6wItKC1dOXuZJ5oFYt2Og7cqrElSQYC9bv-aV7iQ5FDYaJPp-fa7tQNhc2yS0fw3QBu-M",
"type": "ACTIVE",
"conversationToken": "e0e78f40-a207-49c2-9050-50c6ed526c24"
},
"inputs": [
{
"intent": "actions.intent.SIGN_IN",
"rawInputs": [
{
"inputType": "KEYBOARD"
}
],
"arguments": [
{
"name": "SIGN_IN",
"extension": {
"#type": "type.googleapis.com/google.actions.v2.SignInValue",
"status": "OK"
}
},
{
"name": "text"
}
]
}
],
"surface": {
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.ACCOUNT_LINKING"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
},
{
"name": "actions.capability.MEDIA_RESPONSE_AUDIO"
},
{
"name": "actions.capability.WEB_BROWSER"
}
]
},
"isInSandbox": true,
"requestType": "SIMULATOR"
}
this is the response that i provide after verifying the user.
I tried it with both intents actions.intent.TEXT and actions.intent.SIGN_IN but with no success. the next request is provided with the user.idToken property again instead of the user.profile (that should contain the payload)
{
"conversationToken": "b09d915e-6df9-496d-acde-b76858cd95b4",
"expectUserResponse": true,
"expectedInputs": [
{
"inputPrompt": {
"richInitialPrompt": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Hi",
"displayText": "Hi"
}
}
],
"suggestions": []
}
},
"possibleIntents": [
{
"intent": "actions.intent.TEXT",
"inputValueData": {
"#type": "type.googleapis.com/google.actions.v2.SignInValue",
"status": "OK"
}
}
]
}
]
}
The user.profile attribute you're talking about is something that is provided via the actions-on-google library for JavaScript. It isn't in the JSON that you will receive. But...
You don't need it because the basic profile information (name, email, and Google ID) is encoded in the user.idToken. That string, which will be sent to you for every request, is just a JWT token which you can verify and decode. The profile will be in the "payload" section.
I don't know c#, but https://jwt.io/ contains a list of libraries which can decode the JWT string for you so you can read the "payload".
Keep in mind that you don't need to verify the token each time (although if you do it right, this shouldn't be expensive), but that you can decode it to get the information that you're looking for.
If you don't want to decode it, you can decode it when you first verify it, get the information you need, and store that information in the userStorage string (assuming you don't expect it to change).

How to manage Facebook api response data in C# asp.net?

How to convert facebook api response in user readable HTML format?
I call graph api
https://graph.facebook.com/me/feed?access_token=<token>
below is my response data from API.
{
"data": [
{
"id": "100000626589435_240877109276507",
"from": {
"name": "Abhi Patel",
"id": "100000626589435"
},
"type": "status",
"created_time": "2011-08-02T10:36:17+0000",
"updated_time": "2011-08-02T10:36:17+0000"
},
{
"id": "100000626589435_240760105954874",
"from": {
"name": "Abhi Patel",
"id": "100000626589435"
},
"type": "status",
"created_time": "2011-08-02T03:02:21+0000",
"updated_time": "2011-08-02T03:02:21+0000"
},
{
"id": "100000626589435_223775454320006",
"from": {
"name": "Abhi Patel",
"id": "100000626589435"
},
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/274314_100000898272591_5481895_q.jpg",
"link": "http://www.facebook.com/?ref=nf_fr",
"icon": "http://static.ak.fbcdn.net/images/icons/?8:",
"type": "link",
"created_time": "2011-06-28T18:56:44+0000",
"updated_time": "2011-06-28T18:56:44+0000"
}
],
"paging": {
"previous": "<previous link>",
"next": "<next link>"
}
}
also want paging in facebook response data,
I want 20 records from facebook api response. How to manage this things..
Facebook returns raw JSON data. There are no style elements to it. It's up to you to present the data returned in the format you choose. Imagine if Facebook returned HTML and style elements. That wouldn't work very well for desktop applications or mobile devices. Instead, they just give you the raw data, and you design the HTML elements, or the WPF Views, or whatever to show the data you want to show.
By returning the raw data, you can also store it locally in a database for your own queries, or your own applications purposes.
Edited to add: You can parse out the objects by accessing the JSON elements directly, or you can deserialize the result to C# objects.
Console.WriteLine(response.data[0].from.name);
As for paging, you need to parse out the Paging elements. The Facebook C# SDK returns dynamic objects, so you can do something like
string next = response.paging.next;
string prev = response.paging.prev;
And then just make a request to each URL to fetch the data you want.
Use JSON.net and convert into the XML then it would be easy to manage for you.

Categories

Resources