Forum Discussion

moretonblue's avatar
2 years ago

Serialization Error /Contact/Customer

I'm having a serialization error

Followed the docs here 
https://developer.myob.com/api/myob-business-api/v2/contact/customer/
and here

https://accountrightapi.myob.cloud/?version=latest#4a7e7e7e-fab9-45e1-9e80-f4190ff36c27

```json
{
LastName: "test",
FirstName: "test",
IsIndividual: true,
IsActive: true,
DisplayID: "CUS000001",
SellingDetails: {
TaxCode: {
UID: "05bd06d3-ad4d-4249-af58-0a68ca7db9e1",
},
FreightTaxCode: {
UID: "ba799085-c700-4910-ac0b-27035a75af02",
},
},
Addresses: {
Email: "testmyob@moretonblue.com",
Phone1: "11111111111",
},
}
`

snippet of my code

```js

      const newClient = {
        LastName: 'asfasfasfasfasf',
        FirstName: 'asfasfasfasfasfsaf',
        IsIndividual: true,
        IsActive: true,
        DisplayID: 'CUS000001',
        SellingDetails: {
          TaxCode: {
            /** TODO: get on config */
            UID: getTaxUIDByCode('ABN'),
          },

          FreightTaxCode: {
            /** TODO: get on config */
            UID: getTaxUIDByCode('FRE'),
          },
        },
        Addresses: {
          Email: email,
          Phone1: '11111111111',
        },
      };
      const raw = JSON.stringify(newClient);


```
Here is the error after posting to /Contact/Customer

```json
{
Errors: [
{
Name: "SerializationError",
Message: null,
AdditionalDetails: "Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[MYOB.AccountRight.API.Version2.Contracts.Address]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'Addresses.Email', line 1, position 284.",
ErrorCode: 50,
Severity: "Error",
LearnMore: null,
},
],
Information: "Warning, error messages have not been finalised in this release and may change",
}
```

any ideas on why this is happening am I missing something?

3 Replies

Replies have been turned off for this discussion
  • I contacted MYOBapi support, and the answer is that the Addresses section can contain up to 5 addresses and therefore is an array so must have square brackets added...

     

    Addresses: [

    {
    Email: "testmyob@moretonblue.com",
    Phone1: "11111111111",
    }],

  • Celia_B's avatar
    Celia_B
    MYOB Moderator

    Hi moretonblue 

     

    Thanks for you post. 

     

    For any API error/integration related queries, we recommend raising a support request via the following link: https://apisupport.myob.com/hc/en-us/requests/new

     

    Please feel free to post again. I'm happy to assist further. 

     

    If my response has answered your inquiry please click "Accept as Solution" to assist other users find this information.

     

    Best Regards, 

    Cel