Jump to content

Recommended Posts

Posted

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

 

  • Administrators
Posted

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).

  • Administrators
Posted

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

  • Like 1

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...