I have an issue where I can't quite see which .net encoding method to use for setting fields for the above. Here's my code:
Contact Contact = null;
Contacts Contacts = null;
List<Contact> ContactsList = null;
ContactsList = new List<Contact>();
Contacts = new Contacts();
//no error
Contact.BankAccountDetails = "detew";
//400 Bad Request error
Contact.BankAccountDetails = "&ew";
//I have tried encoding using:
System.Uri.EscapeDataString
System.Security.SecurityElement.Escape
System.Net.WebUtility.HtmlEncode
System.Xml.XmlConvert.EncodeName
System.Web.HttpUtility.HtmlEncode
System.Web.HttpUtility.UrlEncode
System.Web.HttpUtility.HtmlAttributeEncode
//But nothing works.
//This is the passed xml with error:
Xero.NetStandard.OAuth2.Client.ApiException: 'Xero API 400 error calling UpdateContact :{
"ErrorNumber": 10,
"Type": "ValidationException",
"Message": "A validation exception occurred",
"Elements": [
{
"ContactID": "89d59636-6524-47b2-b047-0000000000000",
"ContactNumber": "Cust_4",
"AccountNumber": "Cust_4",
"ContactStatus": "ACTIVE",
"Name": "cpName",
"FirstName": "MyCustomerFirstName2",
"LastName": "MyCustomerLastName1",
"EmailAddress": "sfgdg@sdfs.lo",
"SkypeUserName": "",
"BankAccountDetails": "bkname& bankacname sortcode accnumber bicswift iban",
"UpdatedDateUTC": "\/Date(1604408524790)\/",
"ContactGroups": [],
"IsSupplier": false,
"IsCustomer": false,
"ContactPersons": [],
"HasAttachments": false,
"HasValidationErrors": true,
"ValidationErrors": [
{
"Message": "The BankAccountDetails field cannot be more than 50 characters long."
}
]
}
]
}'
Converting to UTF8 (How can I transform string to UTF-8 in C#?) as per thread https://community.xero.com/developer/discussion/32311#answer32331 does not work either.
Maybe I need to set the Content-Type to xml but am not sure how it's done using the Xero DSK. Maybe via XeroConfiguration when the connection is made?
Thanks.