Reginald Jackson Posted March 1, 2021 Share Posted March 1, 2021 Hi, I'm trying to retrieve a list of customer contacts and, for each one, perform some crud processes on another system; this is using c#. I used the api response sample for Get all contacts to copy the resulting json string and used the paste special .. paste as json classes feature of Visual Studio, however when I run my code the Deserialization function doesn't return any data, although the raw json string has returned exactly what I expected. I'm thinking the classes have not been generated correctly for some reason. Here's the first bit of the classes that get generated. { public class SageOneContactRootobject { public SageOneContact[] Property1 { get; set; } } public class SageOneContact { public string id { get; set; } public string displayed_as { get; set; } public string path { get; set; } public DateTime created_at { get; set; } public DateTime updated_at { get; set; } public Link[] links { get; set; } public DateTime deleted_at { get; set; } public int balance { get; set; } and on it goes. I try and Deserialize as follows: string contacturl = "https://api.accounting.sage.com/v3.1/contacts/?attributes=all&contact_type_id=CUSTOMER"; var contactresponse = client.GetAsync(contacturl); var contactcontent = await contactresponse.Result.Content.ReadAsStringAsync(); SageOneContactRootobject SageOneContactRootobject = JsonConvert.DeserializeObject<SageOneContactRootobject>(contactcontent); Am I doing something daft? Cheers Reg Link to comment Share on other sites More sharing options...
Administrators Ben Smith Posted March 2, 2021 Administrators Share Posted March 2, 2021 Hi Reginald, So is the JSON response held in the variable 'contactcontent' correct? Ideally if we could see the value of that variable, to verify the response has been successful that would be a good start. Also as far as I can tell from that, you would need to have defined getters and setters for all of the properties you wish to have available on the SageOneContactRootobject object? It appears in your class definition for SageOneContactRootobject you aren't? If thats correct then you should just be able to use the values of the properties on the newly populated object (SageOneContactRootobject.id etc). Link to comment Share on other sites More sharing options...
Reginald Jackson Posted March 2, 2021 Author Share Posted March 2, 2021 Hi. I thought I'd probably not set up class definitions up correctly, so I used Postman to give me a sample output of all contacts, then found a great website (Convert JSON to C# Classes Online - Json2CSharp Toolkit) that takes a pasted json message and generates the required class structure., and this solved it. Thanks for responding. Reg 2 Link to comment Share on other sites More sharing options...
Administrators Ben Smith Posted March 2, 2021 Administrators Share Posted March 2, 2021 Great stuff, glad you're moving forward 😊 Ben Link to comment Share on other sites More sharing options...
Reginald Jackson Posted March 2, 2021 Author Share Posted March 2, 2021 Very heavy going though :). My trial is running short, is there any scope to extend it by another 30 days? Link to comment Share on other sites More sharing options...
Administrators Ben Smith Posted March 2, 2021 Administrators Share Posted March 2, 2021 Yes, I'll reach out to you via direct message - as a developer we can extend your trial for 12 months free of charge. Ben 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now