0

I'm trying to achieve update contact with Xero api: I'm trying to update AccountNumber value is null.

This is the code for update method. I'm passing value with ContactId and AccountNumber.

        var xContact = new XeroContact
        {
            AccountNumber = null,
            ContactId = CustomerGUID
        };
        var request = new XeroContactRequest { AuthToken = _authHelper.AccessToken, Search = "", TenantId = _authHelper.TenantId, CustomerGUID = CustomerGUID, Contact = xContact };
        var xeroCustomerResult = _xeroContactBusiness.UpdateContact(request);

update function:

public IResult<XeroContact> UpdateContact(XeroContactRequest data)
        {
            var result = new Result<XeroContact>();
            try
            {
                if (data == null || string.IsNullOrEmpty(data.AuthToken) || string.IsNullOrEmpty(data.TenantId)) throw new ArgumentNullException("data is required");

                var client = new RestClient(BaseUrl);
                var method = string.Format("/{0}/{1}", _apiMethod, data.CustomerGUID);
                var request = new RestRequest(method, Method.POST);

                request.AddHeader("Authorization", string.Format("Bearer {0}", data.AuthToken));
                request.AddHeader("Accept", "application/json");
                request.AddHeader("Xero-tenant-id", data.TenantId);

                var postData = JsonConvert.SerializeObject(data.Contact);
                request.AddJsonBody(postData);                                          
                var response = client.Execute(request);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new Exception(ParseError(response.Content));
                }
            }
            catch (Exception ex)
            {
                result.HasData = false;
                result.Data = null;
                result.Error = ex;
            }       
            return result;
        }

Can you please help me understand what I'm doing wrong? How can i update AccountNumber by ContactId. Thanks !

Letoncse
  • 702
  • 4
  • 15
  • 36

1 Answers1

0

I have resolved this issue below way, Just need to send ContactId and those parameter that's need to be updated. Here "AccountNumber" field need to be updated. Thanks !

        var body = new
        {
            ContactId = data.CustomerGUID,
            AccountNumber=""
        };

        var postData = JsonConvert.SerializeObject(body);
        request.AddJsonBody(postData);
Letoncse
  • 702
  • 4
  • 15
  • 36