I have a API response has a structure like shown below. How can I get the values from this Json string?
[
{
"id": xxx,
"profileId": xxx,
"recipientId": xxx,
"creationTime": "xxxx",
"modificationTime": "xxxx",
"active": true,
"eligible": true,
"balances": [
{
"balanceType": "AVAILABLE",
"currency": "EUR",
"amount": {
"value": 55555,
"currency": "EUR"
},
"reservedAmount": {
"value": 0,
"currency": "EUR"
},
"bankDetails": {
"id": xxx,
"currency": "EUR",
"bankCode": "code",
"accountNumber": "account number",
"swift": "swift",
"iban": "iban",
"bankName": "bankName",
"accountHolderName": "accountHolderName",
"bankAddress": {
"addressFirstLine": "bankAddress",
"postCode": "xxxxx",
"city": "xxxxx",
"country": "xxxxx",
"stateCode": null
}
}
}
]
}
]
I am using The below extension method to get data for some other API's I have integrated in my system. This works fine for the other API's I have integrated.
public static string GetJsonField(RestSharp.IRestResponse value, string res)
{
Newtonsoft.Json.Linq.JObject json = Newtonsoft.Json.Linq.JObject.Parse(value.Content);
res = json.GetValue(res).ToString();
return res;
}
Thanks in advance
Copy that Json in json2csharp.com, it will give you the classes that you will need to convert the Json in a c# object.
Then just use var myJson = JsonConverter.deserialize(Json) ;
And you can access to the Json properties as you do with any other class
Related
I am trying to convert the content of a response message to a list of items contained within the response message and keep running into issues, the returned json looks like this:
Jason output
Here is the whole returned response content:
{
"Version": 1,
"Result": "Success",
"Data": {
"Tasks": [
{
"Oid": "f70b1a46-690f-4637-886b-f90f035a11e8",
"CreatedOn": "2022-07-15T00:07:41.553Z",
"ChangedOn": "2022-07-15T03:39:58.373Z",
"Subject": "233817 3693 Range Rd",
"Description": "",
"Comment": "",
"IsStarted": true,
"IsFinished": true,
"IsFinalAppointment": false,
"ScheduledOn": "2022-07-15T09:37:41.553",
"ProductionDeadline": "0001-01-01T00:00:00",
"ScheduledStart": "2022-07-15T09:45:00",
"ScheduledEnd": "2022-07-15T09:50:00",
"RealStart": "2022-07-15T09:45:00",
"RealEnd": "2022-07-15T09:50:00",
"CalculatedSeconds": 300.0000,
"IdleSeconds": 0,
"ScheduledDuration": "PT5M",
"RealDuration": "PT5M",
"Status": 2,
"PercentComplete": 100,
"HasFinishedItems": true,
"IsCustomTask": false,
"AppointmentType": "OrderSpecificAppointment",
"OrderItemCount": 31,
"OrderItemPartsCount": 56,
"MaterialUsageTotal": 58.3280000000,
"MaterialUsageTotalConverted": 58.328,
"MaterialUsageNet": 46.9659000000,
"MaterialUsageNetConverted": 46.9659,
"MaterialUsageScrap": 11.3621000000,
"MaterialUsageScrapConverted": 11.3621,
"MaterialUsageTotalWeight": 263.4676,
"MaterialUsageTotalWeightConverted": 263.4676,
"MaterialUsageNetWeight": 212.1449000000,
"MaterialUsageNetWeightConverted": 212.14490,
"MaterialUsageScrapWeight": 51.3227000000,
"MaterialUsageScrapWeightConverted": 51.32270,
"Station": {
"_Value": "Centurio",
"oid": "f7f3c5fe-49f0-4a9a-b366-29c4ab990fc7"
},
"Materials": [
{
"_Value": "STEALTH MATTE .55 (MONUMENT†)",
"oid": "4889a4f2-75c6-4fb2-b57d-d393ff495ef1",
"externalID": "161539"
}
],
"MaterialCoils": [],
"MaterialDimensions": [],
"PreviousDependencies": [],
"NextDependencies": [
{
"_Value": "",
"oid": "4699df81-4d5c-456c-904d-389a08f60a82",
"start": "2022-07-17T03:37:00",
"station": "Unallocated Folding Station"
}
]
},
{
"Oid": "4699df81-4d5c-456c-904d-389a08f60a82",
"CreatedOn": "2022-07-15T00:07:41.567Z",
"ChangedOn": "2022-07-15T08:27:19.297Z",
"Subject": "233817 3693 Range Rd",
"Description": "",
"Comment": "",
"IsStarted": true,
"IsFinished": true,
"IsFinalAppointment": true,
"ScheduledOn": "2022-07-15T09:37:41.567",
"ProductionDeadline": "0001-01-01T00:00:00",
"ScheduledStart": "2022-07-17T03:37:00",
"ScheduledEnd": "2022-07-17T06:33:00",
"RealStart": "2022-07-17T03:37:00",
"RealEnd": "2022-07-17T06:33:00",
"CalculatedSeconds": 10560.0000,
"IdleSeconds": 0,
"ScheduledDuration": "PT2H56M",
"RealDuration": "PT2H56M",
"Status": 2,
"PercentComplete": 100,
"HasFinishedItems": true,
"IsCustomTask": false,
"AppointmentType": "OrderSpecificAppointment",
"OrderItemCount": 31,
"OrderItemPartsCount": 56,
"MaterialUsageTotal": 46.9659000000,
"MaterialUsageTotalConverted": 46.9659,
"MaterialUsageNet": 46.9659000000,
"MaterialUsageNetConverted": 46.9659,
"MaterialUsageScrap": 0.0000000000,
"MaterialUsageScrapConverted": 0.0,
"MaterialUsageTotalWeight": 212.1449,
"MaterialUsageTotalWeightConverted": 212.1449,
"MaterialUsageNetWeight": 212.1449000000,
"MaterialUsageNetWeightConverted": 212.14490,
"MaterialUsageScrapWeight": 0.0000000000,
"MaterialUsageScrapWeightConverted": 0.00000,
"Station": {
"_Value": "Unallocated Folding Station",
"oid": "7ce5334a-b05c-4511-be7b-1a83d2bf8d4c"
},
"Materials": [
{
"_Value": "STEALTH MATTE .55 (MONUMENT†)",
"oid": "4889a4f2-75c6-4fb2-b57d-d393ff495ef1",
"externalID": "161539"
}
],
"PreviousDependencies": [
{
"_Value": "",
"oid": "f70b1a46-690f-4637-886b-f90f035a11e8",
"start": "2022-07-15T09:45:00",
"station": "Centurio"
}
],
"NextDependencies": []
}
]
},
"Details": ""
}
I wish to extract each task from the "Tasks" element into a list (I have created a class to hold each Task element). So far my code looks like this:
public async void AppointmentsAsync(int taskScheduleID)
{
HttpResponseMessage taskList;
using (RevSchedDataContext context = new RevSchedDataContext())
{
string TimePrint = ConfigurationManager.AppSettings["TimePrint"];
schedule = (from s in context.TaskSchedules.Where(x => x.TaskScheduleID == taskScheduleID) select s).FirstOrDefault();
client.BaseAddress = new Uri("http://bendex.revroof.com.au/microsea/BendexRevBend/import/1.0/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
taskList = await client.GetAsync($"{client.BaseAddress}GetOrderScheduledTasksListJson?did=233817");
var products = await taskList.Content.ReadAsStringAsync();
var mtLists = JsonConvert.DeserializeObject<BendexTaskList>(products);
}
}
When putting a breakpoint on mtLists line and stepping mtLists never get populated.
Regards
Peter
I have found a solution to my problem thanks to the following site: https://json2csharp.com/
This enabled me to create the correct required classes to deserialize the json output in the format required to process.
New calling code:
Root scheduledTaskList = JsonConvert.DeserializeObject<Root>(products);
foreach(var tsk in scheduledTaskList.Data.Tasks)
{
//ToDo: pull required data and update table
}
Regards
Peter
I add 2 composite templates to the envelope,
one of the composites has 2 recipients and 1 document,
the other composite has 1 recipient and 1 document,
however the signature tabs are only shown in the first document.
as shown in the image, the signature tabs are only on the first document
[enter image description here][1]
The Json:
"compositeTemplates": [
{
"document": {
"documentBase64": "xxxx",
"name:": "xxxx",
"documentId":"xxx"
},
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"deliveryMethod": "Email",
"email": "joao#protonmail.com",
"idCheckConfigurationName": "SMS Auth $",
"name": "joao da Silva",
"recipientId": "8c5fcdce-fe94-4379-8df7-608e753db718",
"requireIdLookup": "true",
"roleName": "Assinante",
"routingOrder": "1",
"smsAuthentication": {
"senderProvidedNumbers": [
"+5546994528888"
]
},
"status": "Created",
"tabs": {
"signHereTabs": [
{
"documentId": "1878974182",
"recipientId": "8c5fcdce-fe94-4379-8df7-608e753db718"
}
]
}
},
{
"deliveryMethod": "Email",
"email": "joana#gmail.com",
"idCheckConfigurationName": "SMS Auth $",
"name": "Joana Silva",
"recipientId": "11f6f9fc-c622-4d9b-9a98-4401a59cefbe",
"requireIdLookup": "true",
"roleName": "Testemunha",
"routingOrder": "2",
"smsAuthentication": {
"senderProvidedNumbers": [
"+5546994528888"
]
},
"status": "Created",
"tabs": {
"signHereTabs": [
{
"documentId": "1878974182",
"recipientId": "11f6f9fc-c622-4d9b-9a98-4401a59cefbe"
}
]
}
}
]
},
"sequence": "2"
}
],
"serverTemplates": [
{
"sequence": "1",
"templateId": "9b13a1dc-456c-4dff-87d8-ae4205dfb4eb"
}
]
},
{
"document": {
"documentBase64": "xxxx",
"name:": "xxxx",
"documentId":"xxx"
},
"inlineTemplates": [
{
"recipients": {
"signers": [
{
"deliveryMethod": "Email",
"email": "pedro#outlook.com",
"idCheckConfigurationName": "SMS Auth $",
"name": "Pedro Silva",
"recipientId": "edd53f74-3e87-4380-859a-6d1fee7c5c92",
"requireIdLookup": "true",
"roleName": "Assinante",
"routingOrder": "1",
"smsAuthentication": {
"senderProvidedNumbers": [
"+5546994528888"
]
},
"status": "Created",
"tabs": {
"signHereTabs": [
{
"documentId": "1238654318",
"recipientId": "edd53f74-3e87-4380-859a-6d1fee7c5c92"
}
]
}
}
]
},
"sequence": "3"
}
],
"serverTemplates": [
{
"sequence": "2",
"templateId": "33b13eb1-25d5-46ee-b322-af433665b369"
}
]
}
]
}``
[1]: https://i.stack.imgur.com/HxbX3.jpg
The SignHereTab elements you specified won't show because they are missing something to determine their location. You can either use X/Y coordinates, or you can use anchor strings, but without any information, DocuSign won't know where to place them.
The tags you do see on the first document probably come from the template itself. Note if you meant for all tags to come from the template itself then you have to check the roleName and make sure it matches the role you defined in the template (For which you placed tags for).
as in title, I am trying to use Google API Explorer to run vm instance. I am using instances.insert for this, but I can't get it to work. After successfuly executing the call I can not see any newly creted vm instance in https://console.cloud.google.com/compute/instances
The request I am trying to execute is copied from Equivalent REST request in Google Cloud Console Create an instance web page :
{
"name": "some-name",
"machineType": "projects/my-project-id/zones/europe-west3-c/machineTypes/f1-micro",
"displayDevice": {
"enableDisplay": false
},
"metadata": {
"items": [
{
"key": "startup-script",
"value": "#! /bin/bash\necho hello\nEOF"
}
]
},
"tags": {
"items": []
},
"disks": [
{
"type": "PERSISTENT",
"boot": true,
"mode": "READ_WRITE",
"autoDelete": true,
"deviceName": "some-name",
"initializeParams": {
"sourceImage": "projects/debian-cloud/global/images/debian-10-buster-v20200910",
"diskType": "projects/my-project-id/zones/europe-west3-c/diskTypes/pd-standard",
"diskSizeGb": "10",
"labels": {}
},
"diskEncryptionKey": {}
}
],
"canIpForward": false,
"networkInterfaces": [
{
"subnetwork": "projects/my-project-id/regions/europe-west3/subnetworks/default",
"accessConfigs": [
{
"name": "External NAT",
"type": "ONE_TO_ONE_NAT",
"networkTier": "PREMIUM"
}
],
"aliasIpRanges": []
}
],
"description": "",
"labels": {},
"scheduling": {
"preemptible": false,
"onHostMaintenance": "MIGRATE",
"automaticRestart": true,
"nodeAffinities": []
},
"deletionProtection": false,
"reservationAffinity": {
"consumeReservationType": "ANY_RESERVATION"
},
"serviceAccounts": [
{
"email": "some-number-compute#developer.gserviceaccount.com",
"scopes": [
"https://www.googleapis.com/auth/cloud-platform"
]
}
],
"shieldedInstanceConfig": {
"enableSecureBoot": false,
"enableVtpm": true,
"enableIntegrityMonitoring": true
},
"confidentialInstanceConfig": {
"enableConfidentialCompute": false
}
}
Here is the response with status 200
{
"id": "2981010757915612255",
"name": "operation-1602235056020-5b1396b5c5cee-e0e30499-4d06ce75",
"zone": "https://www.googleapis.com/compute/v1/projects/my-project-id/zones/europe-west3-c",
"operationType": "insert",
"targetLink": "https://www.googleapis.com/compute/v1/projects/my-project-id/zones/europe-west3-c/instances/ams2-linux-race-1",
"targetId": "1541614827291382879",
"status": "RUNNING",
"user": "email#gmail.com",
"progress": 0,
"insertTime": "2020-10-09T02:17:36.818-07:00",
"startTime": "2020-10-09T02:17:36.821-07:00",
"selfLink": "https://www.googleapis.com/compute/v1/projects/my-project-id/zones/europe-west3-c/operations/operation-1602235056020-5b1396b5c5cee-e0e30499-4d06ce75",
"kind": "compute#operation"
}
I have the same issue with C# code example from https://cloud.google.com/compute/docs/reference/rest/v1/instances/insert#examples
I can execute the same request without errors and in response I am getting this
{
"clientOperationId":null,
"creationTimestamp":null,
"description":null,
"endTime":null,
"error":null,
"httpErrorMessage":null,
"httpErrorStatusCode":null,
"id":3283200477858999168,
"insertTime":"2020-10-09T00:46:55.187-07:00",
"kind":"compute#operation",
"name":"operation-1602229614262-5b1382701b989-381126a6-cc145485",
"operationType":"insert",
"progress":0,
"region":null,
"selfLink":"https://www.googleapis.com/compute/v1/projects/my-project-id/zones/europe-west3-c/operations/operation-1602229614262-5b1382701b989-381126a6-cc145485",
"startTime":"2020-10-09T00:46:55.189-07:00",
"status":"RUNNING",
"statusMessage":null,
"targetId":2365846324436118401,
"targetLink":"https://www.googleapis.com/compute/v1/projects/my-project-id/zones/europe-west3-c/instances/some-name",
"user":"email#gmail.com",
"warnings":null,
"zone":"https://www.googleapis.com/compute/v1/projects/my-project-id/zones/europe-west3-c",
"ETag":null
}
but I can't see any new instance beeing created...
Does any one know what is the issue here?
The Compute Engine API is enabled. Result of gcloud services list:
NAME TITLE
...
compute.googleapis.com Compute Engine API
...
Can you please double check if Compute Engine Api is enabled and post the result in your question.
gcloud services list
I believe your Compute Engine Api is not enabled.
When I retrieve a checklist instance, I got the following section related to attachment.
{
"type": "instance_item_attachments",
"id": "5a0a2acf-b02a-4b88-86cc-962c3831bdee",
"attributes": {
"name": "6856ad10-6ab0-11e9-9150-9fda3da0626e.png",
"attachmentType": "OSS",
"mimeType": "image/png",
"uploadStatus": "COMPLETED",
"urns": [
{
"urn": "urn:adsk.wipprod:fs.file:vf.gy4mB910SneymU86Gc4O0A?version=1",
"type": "WIP"
},
{
"urn": "urn:adsk.objects:os.object:wip.dm.prod/ede3de59-1b68-485c-82fe-f1f2af3442fe.png",
"type": "OSS"
},
{
"urn": "urn:adsk.checklists.cs.attachment:58b8afcf-d7cd-49ad-aa10-78c50610761b/5a0a2acf-b02a-4b88-86cc-962c3831bdee",
"type": "CHECKLIST"
}
],
"createdAt": "2019-04-29T18:55:51.334Z",
"updatedAt": "2019-04-29T18:55:54.137Z",
"createdBy": "TAKCJQU6HGXW",
"modifiedBy": "TAKCJQU6HGXW",
"permittedActions": [
"canArchive",
"canEdit"
],
"permittedAttributes": [
"mimeType",
"uploadStatus"
]
},
"links": {
"self": "/containers/58b8afcf-d7cd-49ad-aa10-78c50610761b/instance_item_attachments/5a0a2acf-b02a-4b88-86cc-962c3831bdee"
},
"relationships": {
"container": {
"meta": {
"relation": "primary",
"readOnly": false
},
"links": {
"self": "/containers/58b8afcf-d7cd-49ad-aa10-78c50610761b/instance_item_attachments/5a0a2acf-b02a-4b88-86cc-962c3831bdee/relationships/container",
"related": "/containers/58b8afcf-d7cd-49ad-aa10-78c50610761b/instance_item_attachments/5a0a2acf-b02a-4b88-86cc-962c3831bdee/container"
},
"data": {
"type": "containers",
"id": "58b8afcf-d7cd-49ad-aa10-78c50610761b"
}
},
"item": {
"meta": {
"relation": "primary",
"readOnly": false
},
"links": {
"self": "/containers/58b8afcf-d7cd-49ad-aa10-78c50610761b/instance_item_attachments/5a0a2acf-b02a-4b88-86cc-962c3831bdee/relationships/item",
"related": "/containers/58b8afcf-d7cd-49ad-aa10-78c50610761b/instance_item_attachments/5a0a2acf-b02a-4b88-86cc-962c3831bdee/item"
},
"data": null
}
}
}
Now, I want to download this attachment, the provided URN is: wip.dm.prod/ede3de59-1b68-485c-82fe-f1f2af3442fe.png
If I try to access it using the following link, it says not found
developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/b30e3ffe-333b-446c-b834-e2f2141096b4.png
However, if I changed the URL a bit (by adding objects), it works fine.
developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/b30e3ffe-333b-446c-b834-e2f2141096b4.png
Am I doing something wrong here? or this is a bug in the provided urn?
Adding to Adam Nagy reply, you would need to break the URN. From your original question:
urn:adsk.objects:os.object:wip.dm.prod/ede3de59-1b68-485c-82fe-f1f2af3442fe.png
In .NET you can try (using System.Linq):
string bucketKey = urn.Split("/").First().Split(":").Last();
string objectName = urn.Split("/").Last();
Then rebuild as:
string attachemtnUrl = string.Format("{0}/oss/v2/buckets/{1}/objects/{2}", BASE_URL, bucketKey, objectName);
And you'll also need the Authorization header with a valid access token.
The id / urn of an object in OSS (Object Storage Service) contains the bucket name and object name after the "urn:adsk.objects:os.object:" section.
There is a tutorial on downloading a file https://forge.autodesk.com/en/docs/data/v2/tutorials/download-file/
It shows that the reply concerning an item contains both the id and the actual URL of the download link under the storage section:
"storage": {
"data": {
"type": "objects",
"id": "urn:adsk.objects:os.object:wip.dm.prod/977d69b1-43e7-40fa-8ece-6ec4602892f3.rvt"
},
"meta": {
"link": {
"href": "https://developer.api.autodesk.com/oss/v2/buckets/wip.dm.prod/objects/977d69b1-43e7-40fa-8ece-6ec4602892f3.rvt"
}
}
}
There you can see the connection between the id and the URL you can use to download the file
my aim is to develop a custom search based on goeuro.com(overview) in my spare time.
I simplyfied the search parameters to the minimum.
For example(you can try this, as loong as the search_id is valid):
http://www.goeuro.com/GoEuroAPI/rest/api/v5/results?&search_id=428558909
The search_id will be generated when you visit http://www.goeuro.com and enter the first time your search parameters.
This is the simplified data structure I generated from http://json2csharp.com/ using this as my input JSON:
{
"serviceVersion": "v1.0.0",
"sortVariants": null,
"companies": {
"1007": {
"name": "Eurolines Germany",
"logoUrl": "http://cdn-goeuro.com/static_content/web/logos/{size}/eurolines_germany.png",
"id": "1007"
}
},
"outbounds": {
"3624107261930718525-38-flight-1-27": {
"companyId": "38",
"mode": "flight",
"duration": "873",
"outboundId": "3624107261930718525",
"journeyId": "27",
"departureTime": "2017-01-15T19:12:00.000+01:00",
"arrivalTime": "2017-01-16T09:45:00.000+01:00",
"stops": "1",
"price": 16209,
"updatedAt": "1",
"segments": [ 1344486303, 574447503, 689435565, 833161604 ],
"arrivalOvernightOffset": 1,
"overnightOffset": 1
}
},
"query": {
"roundTrip": false,
"airportToAirport": false,
"locationsOutsideEurope": false,
"searchId": "428558909",
"departurePosition": "377001",
"arrivalPosition": "398532",
"departureDate": "2017-01-15T00:00:00.000+01:00",
"passengers": {
"adults": 1,
"children": 0,
"infants": 0
},
"userInfo": {
"userLocale": "en",
"userCurrency": "EUR"
},
"searchModes": {
"bus": {
"status": "done",
"resultsQty": 13,
"filteredResultsQty": 13
},
"flight": {
"status": "done",
"resultsQty": 276,
"filteredResultsQty": 276
},
"train": {
"status": "done",
"resultsQty": 4,
"filteredResultsQty": 4
}
}
},
"itineraries": [
{ "outboundLegId": "3624107261930718525-38-flight-1-27" }
],
"segmentDetails": {
"1002857016": {
"type": "flight",
"departureTime": "2017-01-16T08:35:00.000+01:00",
"arrivalTime": "2017-01-16T12:05:00.000+02:00",
"departurePosition": "313870",
"arrivalPosition": "314920",
"duration": "150",
"company": "190",
"transportId": "ca6199",
"direction": "OUTBOUND",
"overnightOffset": 1,
"departureOvernightOffset": 1,
"arrivalOvernightOffset": 1
}
},
"positions": {
"2091737": {
"positionType": "busstation",
"name": "Warszawa, Warszawa Centralny",
"cityName": "Warsaw",
"latitude": 52.22782,
"longitude": 21.00224
}
},
"currencies": {
"EUR": {
"name": "Euro",
"symbol": "€"
}
}
}
The result from http://json2csharp.com/ is pretty good, but on the other side it generates something like this
public class Outbounds
{
public __invalid_type__362410726193071852538Flight127 __invalid_name__3624107261930718525-38-flight-1-27 { get; set; }
}
I see two problems here:
using __invalid_name__3624107261930718525-38-flight-1-27 is not a valid identifier in c#
and the above mentioned name is some random name, which I can not rely on my data structure.
So, my actually questions are:
How can I handle the request ?
How shall the data structure look like ?
By the way this is the code I am using(plus the generated results from http://json2csharp.com/):
static void Main()
{
var client = new RestClient("https://www.goeuro.com");
var request = new RestRequest("/GoEuroAPI/rest/api/v5/results?&search_id=428558909", Method.GET);
request.RequestFormat = DataFormat.Json;
// contentType: "application/json; charset=utf-8",
var response = client.Execute<Response>(request).Data;
}
Actually I found an existing solution(partly) for my problem:
https://github.com/evgenTraytyak/goeuro-api
, which is actually written in node.js, but I need c#, but by the way this example does not quite work(only if you have an existing search_id) and at the end I want to get the search_id from goeuro, without manually type it to my code.
Maybe the reason that using this is that the JSON-Format changed...