Posting a new customer (with the friendly code properties)
We suggest to avoid to use the friendly code properties when you post a list of Customers
POST {{url}}/app/Customer/TEST/Folder/{{folder}}
The body of the request will be like this:
{ "$type": "Winbooks.TORM.OM.Customer, Winbooks.TORM.OM", "TotalLevel": 4, "Code": "TEST", "VatApplicable": 1, "IsLocked": false, "IsHidden": false, "MemoType": 0, "Third": { "$type": "Winbooks.TORM.OM.Third, Winbooks.TORM.OM", "TotalLevel": 3, "Code": "TEST", "Name": "The Test Company", "VatNumber": "0000000196", "WebSite": "www.test.be", "Addresses": [ { "$type": "Winbooks.TORM.OM.Address, Winbooks.TORM.OM", "TotalLevel": 2, "Index": 0, "Address1": "Vuchtlaan 78", "Address2": "", "Town": "Antwerpen", "Zip": "2000", "Name": "", "Number": "", "Box": "", "PhoneNo": "+3233215476", "FaxNo": "", "MemoType": 0, "Memo": "", "IsDelivering": true, "IsDeliveringDefault": true, "IsPosting": true, "IsPostingDefault": true, "IsInvoicing": true, "IsInvoicingDefault": true, "CountryCode": "BE" } ], "CivilityCode": "NV", "VatCountryCode": "BE", "LanguageCode": "en", "CurrencyCode": "EUR" }, "VatCode": "21", "CategoryCode": "EU", "GLAccountDefaultCode": "700000", "GLAccountCentralCode": "400000", "PayCodeCode": "30" }
The last level (Addresses) has TotalLevel = 2 because we use the friendly code property (CountryCode). If we use the Id's instead, we have to put TotalLevel = 1 for the last level.
Do not use the DefaultAddress entity which does not support the posting.
Posting a new Customer (with the Id's)
It is more efficient to specify the Id's of the related entities, especially when we post several customers using the same country, civility, language, currency, vat, category, default account, central account or payment term (PayCode).
First, we have to retrieve the Id's:
Request | Id |
---|---|
GET {{url}}/app/Country/BE/Folder/{{folder}} | 4bb898f0-21ba-4ea9-9c35-a74d006cd473 |
GET {{url}}/app/Civility/NV/Folder/{{folder}} | 9bc5b8f4-3682-46c6-ac84-a74d006cd9ad |
GET {{url}}/app/Language/en/Folder/{{folder}} | 4b2d0fa7-ecf7-4883-9e04-a89d00bcd216 |
GET {{url}}/app/Currency/EUR/Folder/{{folder}} | 8d70e1d6-57cf-4bc1-8402-a74d006cd472 |
GET {{url}}/app/Vat/21/Folder/{{folder}} GET {{url}}/app/VatAccount/21/Folder/{{folder}} | d939ccde-90ec-45bb-97fe-a74d006cd718 |
GET {{url}}/app/CustomerCategory/BIG/Folder/{{folder}} | c3613c92-d081-4a94-a245-a8b3005d2391 |
GET {{url}}/app/GLAccount/700000/Folder/{{folder}} | c61c5554-0803-4286-9315-a74d006cd5aa |
GET {{url}}/app/GLAccount/400000/Folder/{{folder}} | 023a99d0-f1e5-45c8-b902-a74d006cd5a8 |
GET {{url}}/app/PayCode/7/Folder/{{folder}} | 48a7b7ab-0f1b-4420-af2e-a74d006cd9a8 |
Or really more efficiently via the ExecuteCriteria:
Request | Body |
---|---|
POST {{url}}/app/Countrys/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Countrys, Winbooks.TORM.OM", "Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["BE"] } ], "ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ], "MaxResult": 1 } |
POST {{url}}/app/Civilitys/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.ThirdCivility, Winbooks.TORM.OM", "Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["NV"] } ], "ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ], "MaxResult": 1 } |
POST {{url}}/app/Languages/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Language, Winbooks.TORM.OM", "Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["en"] } ], "ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ], "MaxResult": 1 } |
POST {{url}}/app/Currencys/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Currency, Winbooks.TORM.OM", |
POST {{url}}/app/VatAccounts/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Accounting.VatAccount, Winbooks.TORM.OM", |
POST {{url}}/app/GLAccounts/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Accounting.GLAccount, Winbooks.TORM.OM", "Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["700000"] } ], "ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ], "MaxResult": 1 } |
POST {{url}}/app/GLAccounts/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Accounting.GLAccount, Winbooks.TORM.OM", "Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["400000"] } ], "ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ], "MaxResult": 1 } |
POST {{url}}/app/PayCodes/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Accounting.PayCode, Winbooks.TORM.OM", |
To post the customer, the body will be then this one:
{ "$type": "Winbooks.TORM.OM.Customer, Winbooks.TORM.OM", "TotalLevel": 3, "Vat_Id": "d939ccde-90ec-45bb-97fe-a74d006cd718", "CustomerCategory_Id": "c3613c92-d081-4a94-a245-a8b3005d2391", "GLAccount_Id": "c61c5554-0803-4286-9315-a74d006cd5aa", "GLAccount2_Id": "023a99d0-f1e5-45c8-b902-a74d006cd5a8", "PayCode_Id": "bee3ad14-c3b0-4284-80e7-a74d006cd9a8", "Code": "TEST2", "VatApplicable": 1, "IsLocked": false, "IsHidden": false, "MemoType": 0, "Third": { "$type": "Winbooks.TORM.OM.Third, Winbooks.TORM.OM", "TotalLevel": 2, "ThirdCivility_Id": "9bc5b8f4-3682-46c6-ac84-a74d006cd9ad",
"VatCountry_Id": "4bb898f0-21ba-4ea9-9c35-a74d006cd473",
"Language_Id": "4b2d0fa7-ecf7-4883-9e04-a89d00bcd216", "Currency_Id": "8d70e1d6-57cf-4bc1-8402-a74d006cd472", "Code": "TEST2", "Name": "The Test Company 2", "VatNumber": "0000000295", "WebSite": "www.test2.be", "Addresses": [ { "$type": "Winbooks.TORM.OM.Address, Winbooks.TORM.OM", "TotalLevel": 1, "Country_Id": "4bb898f0-21ba-4ea9-9c35-a74d006cd473", "Index": 0, "Address1": "Vuchtlaan 79", "Address2": "", "Town": "Antwerpen", "Zip": "2000", "Name": "", "Number": "", "Box": "", "PhoneNo": "+3233215476", "FaxNo": "", "MemoType": 0, "Memo": "", "IsDelivering": true, "IsDeliveringDefault": true, "IsPosting": true, "IsPostingDefault": true, "IsInvoicing": true, "IsInvoicingDefault": true } ] } }
Check if a Customer exists
The best is to use the ExecuteCriteria.
POST {{url}}/app/Customers/Folder/{{folder}}/ExecuteCriteria
The body of the request:
{ "EntityType": "Winbooks.TORM.OM.Customer, Winbooks.TORM.OM", "Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["TEST2"] } ], "ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ], "MaxResult": 1 }
The result:
[ "c961989a-afb3-4c2e-aba0-a8b3008e9942" ]
In case of the customer code does not exist, it returns an empty result.
Update a Customer
You can update the Customer and the Third by the same way you create them but you have to remove the address else it will create a new address. The address has to be updated separately.
POST {{url}}/app/Customer/TEST2/Folder/{{folder}}
The body to update the Customer and the Third is:
{ "$type": "Winbooks.TORM.OM.Customer, Winbooks.TORM.OM", "TotalLevel": 3, "Vat_Id": "d939ccde-90ec-45bb-97fe-a74d006cd718", "CustomerCategory_Id": "c3613c92-d081-4a94-a245-a8b3005d2391", "GLAccount_Id": "c61c5554-0803-4286-9315-a74d006cd5aa", "GLAccount2_Id": "023a99d0-f1e5-45c8-b902-a74d006cd5a8", "PayCode_Id": "bee3ad14-c3b0-4284-80e7-a74d006cd9a8", "Code": "TEST2", "VatApplicable": 1, "IsLocked": false, "IsHidden": false, "MemoType": 9, "Memo": "This is just a comment", "Third": { "$type": "Winbooks.TORM.OM.Third, Winbooks.TORM.OM", "TotalLevel": 2, "ThirdCivility_Id": "9bc5b8f4-3682-46c6-ac84-a74d006cd9ad", "VatCountry_Id": "4bb898f0-21ba-4ea9-9c35-a74d006cd473", "Language_Id": "4b2d0fa7-ecf7-4883-9e04-a89d00bcd216", "Currency_Id": "8d70e1d6-57cf-4bc1-8402-a74d006cd472", "Code": "TEST2", "Name": "The Test Company 2", "VatNumber": "0000000295", "WebSite": "www.test2.be" } }
The TotalLevel of the last level (Third) = 2 else it won't update.
Update the Address
Find the Address Id
First we have to retrieve the Id of the Address of the Third TEST2.
This is the .NET query to do that (with the Winbooks.Apis.Service.dll):
ICriteria criteria = new AddressDAO().CreateCriteria() .CreateAlias("third", typeof(Third), Third.Names.Id, Address.Names.Third_Id) .Add(Condition.Eq("third." + Third.Names.Code, "BEBOP")) .Add(Condition.Eq(Address.Names.IsInvoicingDefault, true)) .SetProjection(Projections.Property(Address.Names.Id)); Newtonsoft.Json.Linq.JArray addressid = _folder.GetFilterAll(criteria.JsonCriteriaSerialize(), "Address");
The corresponding http request is this one:
POST {{url}}/app/Addresss/Folder/{{folder}}/ExecuteCriteria
with the following JSON body:
{ "EntityType": "Winbooks.TORM.OM.Address, Winbooks.TORM.OM", "Alias": "this", "Association": { "third": { "AliasName": "third", "Type": "Winbooks.TORM.OM.Third, Winbooks.TORM.OM", "JoinType": 1, "LeftProperty": "Id", "RightProperty": "Third_Id" } }, "Conditions": [ { "Operator": 0, "PropertyName": "third.Code", "OtherPropertyName": "", "Values": [ "TEST2" ], } ], "ProjectionsList": [ { "PropertyName": "Id", "Operator": 22 } ], }
The result is an array of Id's:
[ "adb4d306-63c9-4d5d-a31a-a8b3008e9946" ]
Update the Address
You have to use the PUT verb in order to update the Address based on the Id which is inside the body. Pay attention at the TotalLevel = 2.
PUT {{url}}/app/Address/Folder/{{folder}}
The body is:
{ "$type": "Winbooks.TORM.OM.Address, Winbooks.TORM.OM", "TotalLevel": 2, "Country_Id": "4bb898f0-21ba-4ea9-9c35-a74d006cd473", "Index": 0, "Address1": "Vuchtlaan 2", "Address2": "", "Town": "Gent", "Zip": "9000", "Name": "", "Number": "", "Box": "", "PhoneNo": "", "FaxNo": "", "MemoType": 0, "Memo": "", "IsDelivering": true, "IsDeliveringDefault": true, "IsPosting": true, "IsPostingDefault": true, "IsInvoicing": true, "IsInvoicingDefault": true,
"Id": "adb4d306-63c9-4d5d-a31a-a8b3008e9946"
}