Adding a Company Entity using the Sage CRM SOAP Web Service API

Less than one minute read time.
Below is some code that will add a company, a default contact (Person) and a default business telephone number. When adding a company entity (with address, email etc) to Sage CRM via the Webservices API, CRM will automatically use the first data item in as the default person, and address etc. It will also automatically denormalise business phone and emails into the company and person records.

[code language="csharp"]
private void button1_Click(object sender, EventArgs e)
{
ewarebase[] CRMBase = new ewarebase[1];
company newCompany = new company();
crmid newRecordID = new crmid();

newCompany.name = "testCompanyName;
newCompany.people= new ewarebaselist();
newCompany.people.records=new ewarebase[1];
newCompany.people.entityname="person";

newCompany.phone = new ewarebaselist();
newCompany.phone.records = new ewarebase[1];
newCompany.phone.entityname = "phone";

person newPerson = new person();
newPerson.firstname="TestFirstName";
newPerson.lastname="TestLastName";
newCompany.people.records[0]=newPerson;

phone newPhone = new phone();
newPhone.type = "Business";
newPhone.countrycode = "44";
newPhone.areacode = "20";
newPhone.number = "7701076";
newCompany.phone.records[0] = newPhone;

CRMBase[0] = newCompany;
addresult CRMAddResult = CRM.add("company", CRMBase);
newRecordID= (crmid) CRMAddResult.records[0];
}
[/code]