C# parse JSON access to child object - c#

I have this JSON:
{
"total": 23695,
"total_pages": 1185,
"results": [{
"id": "r7bVvV7MLdQ",
"created_at": "2018-01-17T06:38:03-05:00",
"updated_at": "2018-05-09T03:35:24-04:00",
"width": 4032,
"height": 2526,
"color": "#F7EDE7",
"description": null,
"urls": {
"raw": "https://images.unsplash.com/photo-1516189050082-44d4deb5ceef?ixlib=rb-0.3.5\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026s=8b6caac6353f390fbbabde8441dd1959",
"full": "https://images.unsplash.com/photo-1516189050082-44d4deb5ceef?ixlib=rb-0.3.5\u0026q=85\u0026fm=jpg\u0026crop=entropy\u0026cs=srgb\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026s=89ca725623d794116d3741907c93ceab",
"regular": "https://images.unsplash.com/photo-1516189050082-44d4deb5ceef?ixlib=rb-0.3.5\u0026q=80\u0026fm=jpg\u0026crop=entropy\u0026cs=tinysrgb\u0026w=1080\u0026fit=max\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026s=666eb6ac25c7fec68d5994545b933726",
"small": "https://images.unsplash.com/photo-1516189050082-44d4deb5ceef?ixlib=rb-0.3.5\u0026q=80\u0026fm=jpg\u0026crop=entropy\u0026cs=tinysrgb\u0026w=400\u0026fit=max\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026s=3dbc611c97d323ff8b4b043cff19317b",
"thumb": "https://images.unsplash.com/photo-1516189050082-44d4deb5ceef?ixlib=rb-0.3.5\u0026q=80\u0026fm=jpg\u0026crop=entropy\u0026cs=tinysrgb\u0026w=200\u0026fit=max\u0026ixid=eyJhcHBfaWQiOjEyMDd9\u0026s=0c760185c35eadb31a7bba9b9794d424"
},
"links": {
"self": "https://api.unsplash.com/photos/r7bVvV7MLdQ",
"html": "https://unsplash.com/photos/r7bVvV7MLdQ",
"download": "https://unsplash.com/photos/r7bVvV7MLdQ/download",
"download_location": "https://api.unsplash.com/photos/r7bVvV7MLdQ/download"
},
"categories": [],
"sponsored": false,
"likes": 0,
"liked_by_user": false,
"current_user_collections": [],
"slug": "cloud-smoke-steam",
"user": {
"id": "G69mdFHx0X0",
"updated_at": "2018-05-03T14:00:07-04:00",
"username": "maxkuk",
"name": "Max Kukurudziak",
"first_name": "Max",
"last_name": "Kukurudziak",
"twitter_username": null,
"portfolio_url": "http://www.instagram.com/makckuk",
"bio": "Product Designer at MacPaw, Lecturer at Projector",
"location": "Kiev, Ukraine",
"links": {
"self": "https://api.unsplash.com/users/maxkuk",
"html": "https://unsplash.com/#maxkuk",
"photos": "https://api.unsplash.com/users/maxkuk/photos",
"likes": "https://api.unsplash.com/users/maxkuk/likes",
"portfolio": "https://api.unsplash.com/users/maxkuk/portfolio",
"following": "https://api.unsplash.com/users/maxkuk/following",
"followers": "https://api.unsplash.com/users/maxkuk/followers"
},
"profile_image": {
"small": "https://images.unsplash.com/profile-1518780839522-ee199eceaf8c?ixlib=rb-0.3.5\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=32\u0026w=32\u0026s=c37d2f2844b45f52c0f66cd580a200c8",
"medium": "https://images.unsplash.com/profile-1518780839522-ee199eceaf8c?ixlib=rb-0.3.5\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=64\u0026w=64\u0026s=93647049c20b6a323870fe0886eee329",
"large": "https://images.unsplash.com/profile-1518780839522-ee199eceaf8c?ixlib=rb-0.3.5\u0026q=80\u0026fm=jpg\u0026crop=faces\u0026cs=tinysrgb\u0026fit=crop\u0026h=128\u0026w=128\u0026s=aff2d13afe9fe418b562b85c226b7e8e"
},
"instagram_username": "makckuk",
"total_collections": 0,
"total_likes": 6,
"total_photos": 56
},
"tags": [{
"title": "cloud"
},
{
"title": "smoke"
},
{
"title": "steam"
},
{
"title": "mountain"
},
{
"title": "volcano"
},
{
"title": "blue"
},
{
"title": "rock"
},
{
"title": "glacier"
},
{
"title": "field"
},
{
"title": "geysir"
},
{
"title": "iceland"
}],
"photo_tags": [{
"title": "cloud"
},
{
"title": "smoke"
},
{
"title": "steam"
},
{
"title": "mountain"
},
{
"title": "volcano"
},
{
"title": "blue"
},
{
"title": "rock"
},
{
"title": "glacier"
},
{
"title": "field"
},
{
"title": "geysir"
},
{
"title": "iceland"
}]
},
I need to get results.profile_image.small I tried it on many ways but I never figured out how to access to profile_image fields.
Basically I want to do something like this:
dynamic array = JsonConvert.DeserializeObject(responz);
foreach (var itemx in array["results"])
{
MessageBox.Show(itemx.profile_image.small.ToString());
}
I spent last few hours figuring it out, searching searching StackOverflow. The last option is do this with regex which would be very stupid thing to do.

Based on your JSON, the actual path should be:
itemx.user.profile_image.small
So if you modify your code to include the missing "user" portion:
dynamic array = JsonConvert.DeserializeObject(responz);
foreach (var itemx in array["results"])
{
MessageBox.Show(itemx.user.profile_image.small.ToString());
}
That should solve your problem.
However, this problem would likely not have presented itself if you were using a concrete class to deserialize into. You would have type safety and the assistance of Intelisense if you use a concrete class. You can easily convert your JSON sample into a concrete class using Json2CSharp or using the "Paste as Class" function of modern Visual Studio versions.

Related

ASP.NET Core Web API not working on Azure

I'm pretty new to this subject, but I've written a ASP.NET Core Web API using .Net 5. This API just reads and writes values to a Azure DB. It works perfectly fine on my machine, but after the upload/publish to Azure I get an "500 - Internal Server error"
{
"statusCode": 500,
"message": "Internal server error",
"activityId": "15ed7068-cb40-4e79-8205-cc4c6d4be8be"
}
I've followed the Microsoft Doc for pubishing my API: https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-api-management-using-vs?view=aspnetcore-5.0
Once I got to the step https://learn.microsoft.com/en-us/aspnet/core/tutorials/publish-to-azure-api-management-using-vs?view=aspnetcore-5.0 it doesn't work anymore. Here is the trace:
api-inspector (0.238 ms)
{
"request": {
"method": "GET",
"url": "http://xxx.azure-api.net/v1/Tests",
"headers": [
{
"name": "sec-ch-ua",
"value": "\"Chromium\";v=\"92\",\" Not A;Brand\";v=\"99\",\"Google Chrome\";v=\"92\""
},
{
"name": "sec-ch-ua-mobile",
"value": "?0"
},
{
"name": "Ocp-Apim-Subscription-Key",
"value": ""
},
{
"name": "Sec-Fetch-Site",
"value": "cross-site"
},
{
"name": "Sec-Fetch-Mode",
"value": "cors"
},
{
"name": "Sec-Fetch-Dest",
"value": "empty"
},
{
"name": "X-Forwarded-For",
"value": "xxx.xxx.xxx.xxx"
},
{
"name": "Cache-Control",
"value": "no-cache, no-store"
},
{
"name": "Connection",
"value": "Keep-Alive"
},
{
"name": "Content-Type",
"value": "text/plain;charset=UTF-8"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,br"
},
{
"name": "Accept-Language",
"value": "en,de;q=0.9,en-US;q=0.8,it;q=0.7,it-IT;q=0.6,und;q=0.5"
},
{
"name": "Host",
"value": "xxx.azure-api.net"
},
{
"name": "Referer",
"value": "https://apimanagement.hosting.portal.azure.net/"
}
]
}
}
api-inspector (0.003 ms)
{
"configuration": {
"api": {
"from": "/v1",
"to": {
"scheme": "https",
"host": "xxx.azurewebsites.net",
"port": 80,
"path": "/",
"queryString": "",
"query": {},
"isDefaultPort": false
},
"version": null,
"revision": "1"
},
"operation": {
"method": "GET",
"uriTemplate": "/Tests"
},
"user": "-",
"product": "-"
}
}
cors (0.020 ms)
"Origin header was missing or empty and the request was classified as not cross-domain. CORS policy was not applied."
Backend
(25.737 ms)↑ Back to top
forward-request (0.093 ms)
{
"message": "Request is being forwarded to the backend service. Timeout set to 300 seconds",
"request": {
"method": "GET",
"url": "https://xxx.azurewebsites.net:80/Tests",
"headers": [
{
"name": "Host",
"value": "xxx.azurewebsites.net:80"
},
{
"name": "sec-ch-ua",
"value": "\"Chromium\";v=\"92\",\" Not A;Brand\";v=\"99\",\"Google Chrome\";v=\"92\""
},
{
"name": "sec-ch-ua-mobile",
"value": "?0"
},
{
"name": "Ocp-Apim-Subscription-Key",
"value": ""
},
{
"name": "Sec-Fetch-Site",
"value": "cross-site"
},
{
"name": "Sec-Fetch-Mode",
"value": "cors"
},
{
"name": "Sec-Fetch-Dest",
"value": "empty"
},
{
"name": "X-Forwarded-For",
"value": "xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx"
},
{
"name": "Cache-Control",
"value": "no-cache, no-store"
},
{
"name": "Content-Type",
"value": "text/plain;charset=UTF-8"
},
{
"name": "Accept",
"value": "*/*"
},
{
"name": "Accept-Encoding",
"value": "gzip,deflate,br"
},
{
"name": "Accept-Language",
"value": "en,de;q=0.9,en-US;q=0.8,it;q=0.7,it-IT;q=0.6,und;q=0.5"
},
{
"name": "Referer",
"value": "https://apimanagement.hosting.portal.azure.net/"
}
]
}
}
forward-request (25.643 ms)
{
"messages": [
"The underlying connection was closed: An unexpected error occurred on a send.",
"Error occured while calling backend service.",
"The handshake failed due to an unexpected packet format."
]
}
I've already tried making a completely new project and republishing that one, without success.
I have the same issue, I solved it by changing the port from 80 to 443(if u use HTTPS). Hope it will help u. Or u can reference this https://github.com/ThreeMammals/Ocelot/issues/912

can't put content from restsharp to db

I am working with some API in C# Winforms. Getting response successfully as a json. The problem is that when I deserialize it the output is just a big string like this:
{"orders": [
{
"id": 155971090,
"date_created": "2021-06-18T06:16:31.36202+03:00",
"date_modified": "2021-06-19T15:10:45.567327+03:00",
"client_first_name": "Олександр",
"client_second_name": "",
"client_last_name": "Бандура",
"client_id": 133374423,
"client_avg_rating": 5.0,
"email": "bandurao#ukr.net",
"phone": "+380996461421",
"delivery_option": {
"id": 13662439,
"name": "Доставка \"Нова Пошта\""
},
"delivery_address": "Ананьїв, №1: вул. Незалежності, 19",
"delivery_provider_data": {
"provider": "nova_poshta",
"type": "W2W",
"sender_warehouse_id": null,
"recipient_warehouse_id": "4049834c-e1c2-11e3-8c4a-0050568002cf",
"declaration_number": null
},
"delivery_cost": 0,
"payment_option": {
"id": 7451891,
"name": "Передоплата"
},
"payment_data": null,
"price": "169,72 грн.",
"full_price": "169,72 грн.",
"client_notes": "",
"products": [
{
"id": 1430223923,
"external_id": "513.4769",
"name": "Ремень 4L-240",
"name_multilang": {
"ru": "Ремень 4L-240",
"uk": "Ремінь 4L-240"
},
"sku": "4769",
"price": "21,76 грн.",
"quantity": 1.0,
"measure_unit": "шт.",
"image": "https://images.ua.prom.st/3169964688_w100_h100_remen-4l-240.jpg",
"url": "https://teomax.com.ua/p1430223923-remen-240.html",
"total_price": "21,76 грн.",
"cpa_commission": {
"amount": "1.00"
}
},
{
"id": 1430222732,
"external_id": "512.4825",
"name": "Ремень 240 PJ3",
"name_multilang": {
"ru": "Ремень 240 PJ3",
"uk": "Ремінь 240 PJ3"
},
"sku": "4825",
"price": "48,96 грн.",
"quantity": 1.0,
"measure_unit": "шт.",
"image": "https://images.ua.prom.st/3170015051_w100_h100_remen-240-pj3.jpg",
"url": "https://teomax.com.ua/p1430222732-remen-240-pj3.html",
"total_price": "48,96 грн.",
"cpa_commission": {
"amount": "2.25"
}
},
{
"id": 1430230819,
"external_id": "297.2885",
"name": "Масло \"двухтактное\" (2Т), 1л",
"name_multilang": {
"ru": "Масло \"двухтактное\" (2Т), 1л",
"uk": "Масло \"двотактне\" (2Т), 1л"
},
"sku": "2885",
"price": "99 грн.",
"quantity": 1.0,
"measure_unit": "шт.",
"image": "https://images.ua.prom.st/3169999571_w100_h100_maslo-dvuhtaktnoe-2t.jpg",
"url": "https://teomax.com.ua/p1430230819-maslo-dvuhtaktnoe.html",
"total_price": "99 грн.",
"cpa_commission": {
"amount": "4.55"
}
}
],
"status": "delivered",
"status_name": "Выполнен",
"source": "portal",
"price_with_special_offer": null,
"special_offer_discount": null,
"special_offer_promocode": null,
"has_order_promo_free_delivery": false,
"cpa_commission": {
"amount": "7.80",
"is_refunded": false
},
"utm": null
},
{
"id": 155896081,
"date_created": "2021-06-17T13:11:40.241146+03:00",
"date_modified": "2021-06-17T13:42:55.021203+03:00",
"client_first_name": "Антон",
"client_second_name": "",
"client_last_name": "Подосельник",
"client_id": 133299120,
"client_avg_rating": 5.0,
"email": "a.n.podoselnik#gmail.com",
"phone": "+380992764450",
"delivery_option": {
"id": 13662439,
"name": "Доставка \"Нова Пошта\""
},
"delivery_address": "Киев, №132 (до 30 кг): просп. Леся Курбаса, 16-А",
"delivery_provider_data": {
"provider": "nova_poshta",
"type": "W2W",
"sender_warehouse_id": null,
"recipient_warehouse_id": "51b6c251-7a06-11e4-acce-0050568002cf",
"declaration_number": null
},
"delivery_cost": 0,
"payment_option": {
"id": 7451890,
"name": "Готівкою"
},
"payment_data": null,
"price": "254,30 грн.",
"full_price": "254,30 грн.",
"client_notes": "",
"products": [
{
"id": 1430208419,
"external_id": "250.4391",
"name": "Подшипник шариковый 12*30*8",
"name_multilang": {
"ru": "Подшипник шариковый 12*30*8",
"uk": "Підшипник кульковий 12*30*8"
},
"sku": "4391",
"price": "50,86 грн.",
"quantity": 5.0,
"measure_unit": "шт.",
"image": "https://images.ua.prom.st/3169911780_w100_h100_podshipnik-sharikovyj-12308.jpg",
"url": "https://teomax.com.ua/p1430208419-podshipnik-sharikovyj-12308.html",
"total_price": "254,30 грн.",
"cpa_commission": {
"amount": "5.08"
}
}
],
"status": "canceled",
"status_name": "Отменен",
"source": "portal",
"price_with_special_offer": null,
"special_offer_discount": null,
"special_offer_promocode": null,
"has_order_promo_free_delivery": false,
"cpa_commission": {
"amount": "5.08",
"is_refunded": true
},
"utm": null
},
{
"id": 155881650,
"date_created": "2021-06-17T11:36:11.87828+03:00",
"date_modified": "2021-06-17T13:10:11.527256+03:00",
"client_first_name": "Антон",
"client_second_name": "",
"client_last_name": "Подосельник",
"client_id": 133299120,
"client_avg_rating": 5.0,
"email": "a.n.podoselnik#gmail.com",
"phone": "+380992764450",
"delivery_option": {
"id": 13662439,
"name": "Доставка \"Нова Пошта\""
},
"delivery_address": "Киев, №132 (до 30 кг): просп. Леся Курбаса, 16-А",
"delivery_provider_data": {
"provider": "nova_poshta",
"type": "W2W",
"sender_warehouse_id": null,
"recipient_warehouse_id": "51b6c251-7a06-11e4-acce-0050568002cf",
"declaration_number": null
},
"delivery_cost": 0,
"payment_option": {
"id": 7451890,
"name": "Готівкою"
},
"payment_data": null,
"price": "305,16 грн.",
"full_price": "305,16 грн.",
"client_notes": "",
"products": [
{
"id": 1430208419,
"external_id": "250.4391",
"name": "Подшипник шариковый 12*30*8",
"name_multilang": {
"ru": "Подшипник шариковый 12*30*8",
"uk": "Підшипник кульковий 12*30*8"
},
"sku": "4391",
"price": "50,86 грн.",
"quantity": 6.0,
"measure_unit": "шт.",
"image": "https://images.ua.prom.st/3169911780_w100_h100_podshipnik-sharikovyj-12308.jpg",
"url": "https://teomax.com.ua/p1430208419-podshipnik-sharikovyj-12308.html",
"total_price": "305,16 грн.",
"cpa_commission": {
"amount": "6.10"
}
}
],
"status": "canceled",
"status_name": "Отменен",
"source": "portal",
"price_with_special_offer": null,
"special_offer_discount": null,
"special_offer_promocode": null,
"has_order_promo_free_delivery": false,
"cpa_commission": {
"amount": "6.10",
"is_refunded": true
},
"utm": null
}
]}
My function to get this is like this:
public IRestResponse GetOrders()
{
var connection = new RestClient("https://my.prom.ua/api/v1/");
connection.UseNewtonsoftJson();
var request = new RestRequest("orders/list", Method.GET, DataFormat.None);
request.AddHeader("authorization", "Bearer token");
var response = connection.Get(request);
//var things = JsonConvert.DeserializeObject<Dictionary<string, string>>(response.Content);
Console.WriteLine(response.Content);
return response;
}
Then I tried to make json object out of it and deserialize:
var jsonString = JToken.Parse(data.Content);
var obj = JObject.Parse(jsonString.ToString());
How can I make key value pair out of this and be able to put data into a db table?

c# json as not pulling data

I'm trying to pull some data but it doesn't parse as json, how can i do this, is there anyone who can throw it as code?
my code
var begendurum = await client.GetStringAsync("https://eu.mspapis.com/profilegeneratedcontent/v2/profiles/" + gonderilecek + "/games/j68d/content");
var jsonContent = JObject.Parse(begendurum);
var sondurum = jsonContent[0]["id"].ToString();
Console.Write(sondurum);
json body:
[{
"addedDate": "2021-03-21T09:15:36.6030275+00:00",
"complexity": 0,
"defaultSnapshotType": "snapshot",
"gameId": "j68d",
"id": "4037c9a6ef8e45f18094bfaa570d2977",
"lastEditedDate": "2021-03-21T09:15:36.8996736+00:00",
"lifecycleStatus": "Active",
"owner": "00037853cc134d4cbe970b6aedebe21d",
"participantIds": ["00037853cc134d4cbe970b6aedebe21d"],
"privacyStatus": "Public",
"publishedDate": "2021-03-21T09:15:36.8996736+00:00",
"type": "WAYD",
"resources": [{
"id": "profiles/00037853cc134d4cbe970b6aedebe21d/j68d/wayd/4037c9a6ef8e45f18094bfaa570d2977/437e53a188414c7b96058a15790f660d",
"type": "PgcV1"
}]
}, {
"addedDate": "2021-03-21T09:13:06.0389296+00:00",
"complexity": 0,
"defaultSnapshotType": "snapshot",
"gameId": "j68d",
"id": "55335bca6496404587f90e0d4a1adb24",
"lastEditedDate": "2021-03-21T09:13:06.2070069+00:00",
"lifecycleStatus": "Active",
"owner": "00037853cc134d4cbe970b6aedebe21d",
"participantIds": ["00037853cc134d4cbe970b6aedebe21d"],
"privacyStatus": "Public",
"publishedDate": "2021-03-21T09:13:06.2070069+00:00",
"type": "WAYD",
"resources": [{
"id": "profiles/00037853cc134d4cbe970b6aedebe21d/j68d/wayd/55335bca6496404587f90e0d4a1adb24/37d1d9eb02a24842bd3f10b50bca2213",
"type": "PgcV1"
}]
}, {
"addedDate": "2021-03-21T08:58:37.6752327+00:00",
"complexity": 0,
"defaultSnapshotType": "snapshot",
"gameId": "j68d",
"id": "aa1f7e060c88418f9c7815665922d304",
"lastEditedDate": "2021-03-21T08:58:38.1642128+00:00",
"lifecycleStatus": "Active",
"owner": "00037853cc134d4cbe970b6aedebe21d",
"participantIds": ["00037853cc134d4cbe970b6aedebe21d"],
"privacyStatus": "Public",
"publishedDate": "2021-03-21T08:58:38.1642128+00:00",
"type": "WAYD",
"resources": [{
"id": "profiles/00037853cc134d4cbe970b6aedebe21d/j68d/wayd/aa1f7e060c88418f9c7815665922d304/6333938ca3114a56bcb150cd7b1d9bd5",
"type": "PgcV1"
}]
}, {
"addedDate": "2021-03-21T08:19:08.0288282+00:00",
"complexity": 0,
"defaultSnapshotType": "full",
"gameId": "j68d",
"id": "083b37b1c18c49228771e16183a88436",
"lastEditedDate": "2021-03-21T08:19:08.0288282+00:00",
"lifecycleStatus": "Active",
"owner": "00037853cc134d4cbe970b6aedebe21d",
"participantIds": [],
"privacyStatus": "Public",
"publishedDate": "2021-03-21T08:19:08.0288282+00:00",
"type": "avatar",
"resources": [{
"id": "profiles/00037853cc134d4cbe970b6aedebe21d/j68d/avatar/083b37b1c18c49228771e16183a88436/ad8ff2491104489da5a98ea31ee02fe4",
"type": "PgcV1"
}, {
"id": "profiles/00037853cc134d4cbe970b6aedebe21d/j68d/avatar/083b37b1c18c49228771e16183a88436/9e0298665ae6446ab80f8fe9bfb43a54.png",
"type": "face"
}, {
"id": "profiles/00037853cc134d4cbe970b6aedebe21d/j68d/avatar/083b37b1c18c49228771e16183a88436/6caeef28c90846bda5cf9a71470c2be0.png",
"type": "full"
}]
}]
Use Json.Parse(begendurum);
var begendurum = await client.GetStringAsync("https://eu.mspapis.com/profilegeneratedcontent/v2/profiles/" + gonderilecek + "/games/j68d/content");
var jsonContent = Json.Parse(begendurum);
var sondurum = jsonContent[0]["id"].ToString();
Console.Write(sondurum);

Is there a way to sum the values directly in C# without hitting cosmosDB and run a query?

I am trying to find a way to sum the prices held in an array, the way I am doing it now is to save the document to CosmosDB then run an additional sum(foo) query on it but I am thinking there must be a way so simply do that directly before I save the document to CosmosDB to save the extra round trip to the DocumentDB.
Example Document below.
The values I want to summarise are under:
ApiInputObject.TransactionDetails.Items.Price and there can of course be many items in the array.
I can only figure out how to get a single value out but that seems very inefficient.
{
"InternalTransactionlId": "XXX",
"DocumentType": "order",
"ExternalTransactionId": "externalIdTest2",
"OrderBotResponse": {
"id": "XXX",
"status": "pending",
"checkoutUrl": "https://www.example.com",
"items": [
{
"attributes": {
"color": "Midnight blue",
"size": "L"
},
"price": "500",
"quantity": "1",
"shipping": "0.0",
"title": "ACME Title",
"url": "https://example.com",
"product_id": "XXX",
"imageUrl": "https://example.com/image.jpg",
"status": "pending",
"shippingMethod": "default",
"totalPrice": 500
}
],
"reference": "XXX",
"currency": "SEK",
"country": "SE",
"language": "sv-se",
"provider": "acme",
"callback": {
"refund": "http://example.com",
"success": "http://example.com"
},
"shippingAddress": {},
"logs": [
{
"t": "2019-08-24T20:58:04.844+08:00",
"m": "Created"
}
],
"meta": {
"error": 0
}
},
"ApiInputObject": {
"ApiKey": "XXX",
"OrderType": "directTransaction",
"SourceSystem": {
"SourceSystemName": "ACME"
},
"SourceSystemCountry": "SE",
"DestinationSystem": {
"DestinationSystemName": "acme.com"
},
"DestinationSystemCountry": {
"DestinationSystemCountryName": "SE"
},
"Brand": {
"BrandName": "ACME"
},
"RequestedFeatures": [
"NONE"
],
"ExternalTransactionId": "externalIdTest2",
"TransactionDetails": {
"callback": {
"refund": "http://example.com",
"success": "http://example.com"
},
"items": [
{
"attributes": {
"color": "Midnight blue",
"size": "L"
},
"price": "500",
"quantity": "1",
"shipping": "0.0",
"title": "ACME",
"url": "https://example.com"
}
],
"test": "true",
"reference": "XXX"
}
},
"id": "XXX",
"_rid": "XXX",
"_self": "XXX",
"_etag": "XXX",
"_attachments": "attachments/",
"_ts": 111
}
You can try to use SelectToken to get your JSON data value. then use linq SUM
JObject obj = JObject.Parse(data);
var value = obj.SelectToken("ApiInputObject.TransactionDetails.items").Sum(x=>((int)x["price"]));
c# online

Microsoft Teams - "MultichoiceInput" in Office 365 Card not working

I'm developing a program to extend some functionality from our helpdesk software to Microsoft Teams, using a connector.
This card will have a dropdown-menu where you can choose which person to assign the case to.
The card is successfully posted, but when i click the dropdown menu in the card nothing happens. I know the display-value pair is correctly set, because if I set "isMultiSelect" to true it displays my choices (but this is not going to be multi select, so I cant have it).
Here is the code example from Microsoft I'm using, look at the "Example connector message" - and below is my JSON. I believe it is correct according to the example.
JSON:
{
"summary": "my summary",
"title": "Main title",
"sections": [
{
"activitySubtitle": "ActivitySubtitle",
"activityImage": "http://www.ironmagazine.com/wp-content/uploads/arnold-schwarzenegger-420x327.jpg",
"activityTitle": "ActivityTitle",
"activityText": "ActivityText"
},
{
"facts": [
{
"value": "Facts1 - value",
"name": "Facts1 - name"
},
{
"value": "Facts2 - value",
"name": "Facts2 - name"
}
],
"title": "See more - Tittel "
}
],
"potentialAction": [
{
"actions": [
{
"name": "Add comment",
"target": "http://www.vg.no",
"#type": "HttpPost"
}
],
"inputs": [
{
"target": "https://www.vg.no",
"id": "Comment",
"#type": "TextInput"
}
],
"name": "Add comment",
"#type": "Actioncard"
},
{
"actions": [
{
"name": "Save",
"target": "http://www.vg.no",
"#type": "HttpPost"
}
],
"inputs": [
{
"title": "enter a due date",
"id": "dueDate",
"#type": "DateInput"
}
],
"name": "Set due date",
"#type": "Actioncard"
},
{
"actions": [
{
"name": "Save",
"target": "http://www.vg.no",
"#type": "HttpPost"
}
],
"inputs": [
{
"title": "Assign case to..",
"isMultiSelect": "false",
"choices": [
{
"value": "1",
"display": "Person1"
},
{
"value": "2",
"display": "Person2"
},
{
"value": "3",
"display": "Person3"
},
{
"value": "4",
"display": "Person4"
}
],
"id": "list",
"#type": "MultichoiceInput"
}
],
"name": "Assign case",
"#type": "Actioncard"
}
],
"text": "Main text"
}
Here is how my card is looking now: Imgur
Can anyone tell me what I am doing wrong - or perhaps there is a bug here?
Thanks in advance,
Arve
I was trying the JSON payload and it worked fine. Please try this paylod once and let us know if you still see the issue.
{
"summary": "my summary",
"title": "Main title",
"sections": [{
"activitySubtitle": "ActivitySubtitle",
"activityImage": "http://www.ironmagazine.com/wp-content/uploads/arnold-schwarzenegger-420x327.jpg",
"activityTitle": "ActivityTitle",
"activityText": "ActivityText"
}, {
"facts": [{
"value": "Facts1 - value",
"name": "Facts1 - name"
}, {
"value": "Facts2 - value",
"name": "Facts2 - name"
}
],
"title": "See more - Tittel "
}
],
"potentialAction": [{
"actions": [{
"name": "Add comment",
"target": "http://www.vg.no",
"#type": "HttpPOST"
}
],
"inputs": [{
"target": "https://www.vg.no",
"id": "Comment",
"#type": "TextInput"
}
],
"name": "Add comment",
"#type": "ActionCard"
}, {
"actions": [{
"name": "Save",
"target": "http://www.vg.no",
"#type": "HttpPOST"
}
],
"inputs": [{
"title": "enter a due date",
"id": "dueDate",
"#type": "DateInput"
}
],
"name": "Set due date",
"#type": "ActionCard"
}, {
"actions": [{
"name": "Save",
"target": "http://www.vg.no",
"#type": "HttpPOST"
}
],
"inputs": [{
"title": "Assign case to..",
"isMultiSelect": "false",
"choices": [{
"value": "1",
"display": "Person1"
}, {
"value": "2",
"display": "Person2"
}, {
"value": "3",
"display": "Person3"
}, {
"value": "4",
"display": "Person4"
}
],
"id": "list",
"#type": "MultichoiceInput"
}
],
"name": "Assign case",
"#type": "ActionCard"
}
],
"text": "Main text"}
Regards,
Vasant

Categories