Posting a new Document
First, we have to retrieve the Id of the address. This can be done by 2 ways.
If we manage the contact person in the document, we should also retrieve the Id of the contact.
Load the third BEBOP
GET {{url}}/app/Third/BEBOP/Folder/{{folder}}?MaxLevel=2
The property DefaultAddress.Id give you this Id (56e918d4-0cc0-42db-a040-a89b00aa382d).
This request generates several SQL queries to fetch all the sub-entities (MaxLevel=2 to get the DefaultAddress), and we don't need most of the sub-entities.
Make a query
It's really more efficient to use queries and especially queries with projection to get just what we need. This can be done with the /ExecuteCriteria suffixe.
POST {{url}}/app/Addresss/Folder/{{folder}}/ExecuteCriteria
The body of the request contains the criteria corresponding to this query in .NET:
|
Body for the ExecuteCriteria in JSON:
{ "EntityType": "Winbooks.TORM.OM.Address, Winbooks.TORM.OM", "DAOType": "Winbooks.TORM.DAL.AddressDAO, Winbooks.TORM.DAL", "IsCustomization": false, "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": ["BEBOP"], "ValueTypes": ["System.String, mscorlib"] }, { "Operator": 0, "PropertyName": "IsInvoicingDefault", "OtherPropertyName": "", "Values": [true], "ValueTypes": ["System.Boolean, mscorlib"] } ], "Havings": [], "ProjectionsList": [ { "PropertyName": "Id", "Operator": 22 } ], "Orders": [], "Params": {}, "FirstResult": -1, "MaxResult": -1, "ResultState": 0, "TimeOutSeconds": 0 }
The answer is the id of the default address for invoicing.
[ "56e918d4-0cc0-42db-a040-a89b00aa382d" ]
Post the DocumentHeader (using the friendly code properties)
POST {{url}}/app/DocumentHeader/Folder/{{folder}}
The body of the request contains the document to post like this:
{ "$type": "Winbooks.TORM.OM.Logistics.DocumentHeader, Winbooks.TORM.OM", "TotalLevel": 4, "CurrencyRate": 1, "Number": 2018004, "Date": "/Date(1521028391000)/", "DueDate": "/Date(1521590400000)/", "IsVatIncluded": false, "IsInitial": true, "TotalBase": 500, "TotalVat": 102.38, "TotalToPay": 602.38, "TotalQuantity": 3, "ComputingMethod": 1, "Addressing": { "$type": "Winbooks.TORM.OM.Logistics.DocumentAddressing, Winbooks.TORM.OM", "TotalLevel": 1, "DeliveringAddress_Id": "56e918d4-0cc0-42db-a040-a89b00aa382d", "InvoicingAddress_Id": "56e918d4-0cc0-42db-a040-a89b00aa382d", "PostingAddress_Id": "56e918d4-0cc0-42db-a040-a89b00aa382d", }, "Details": [ { "$type": "Winbooks.TORM.OM.Logistics.DocumentDetail, Winbooks.TORM.OM", "TotalLevel": 3, "RowNumber": 1000, "Quantity": 2, "Amount": 200, "Row": { "$type": "Winbooks.TORM.OM.Logistics.DocumentRow, Winbooks.TORM.OM", "TotalLevel": 2, "Name": "Wheel", "UnitPrice": 100, "DiscountRate": 0, "Comment": "", "VatCode": "21", "ItemCode": "WHEEL" } }, { "$type": "Winbooks.TORM.OM.Logistics.DocumentDetail, Winbooks.TORM.OM", "TotalLevel": 3, "RowNumber": 2000, "Quantity": 1, "Amount": 300, "Row": { "$type": "Winbooks.TORM.OM.Logistics.DocumentRow, Winbooks.TORM.OM", "TotalLevel": 2, "Name": "Frame", "UnitPrice": 300, "DiscountRate": 0, "Comment": "", "VatCode": "21", "ItemCode": "FRAME" } } ], "JournalLogCode": "ORDER", "CustomerCode": "BEBOP", "CurrencyCode": "EUR", "PayCodeCode": "7" }
At the last level (Row), we have to specify "TotalLevel":2 because we use friendly code property (VatCode and ItemCode).
If you use the Id's (which is more efficient), at the last level, you should specify "TotalLevel":1.
The answer give the reference to the created DocumentHeader.
{ "Href": "https://stg-api.winbooksonweb.be/app/DocumentHeader/6caa4a57-4db0-464a-834d-a8aa00ae41a4/Folder/JF_TEST_RESTAPI" }
Post the DocumentHeader (using the Id's)
It is more efficient to specify the Id's of the related entities, especially when we post several documents using the same journal or customer or items or vat or currency.
First, we have to retrieve the Id's:
Request | Id |
---|---|
GET {{url}}/app/Vat/21/Folder/{{folder}} | d939ccde-90ec-45bb-97fe-a74d006cd718 |
GET {{url}}/app/Item/WHEEL/Folder/{{folder}} | 9976a7a9-f27b-4d5d-a414-a8a300c385ad |
GET {{url}}/app/Item/FRAME/Folder/{{folder}} | 41ec5756-f160-4d4f-909c-a8a300c3caea |
GET {{url}}/app/JournalLog/ORDER/Folder/{{folder}} | 1104bd81-fac3-498d-bdb1-a74d006d9096 |
GET {{url}}/app/Customer/BEBOP/Folder/{{folder}} | f5e92880-31c0-43af-9348-a85d0117d78b |
GET {{url}}/app/Currency/EUR/Folder/{{folder}} | 8d70e1d6-57cf-4bc1-8402-a74d006cd472 |
GET {{url}}/app/PayCode/7/Folder/{{folder}} | 48a7b7ab-0f1b-4420-af2e-a74d006cd9a8 |
Or really more efficiently via the ExecuteCriteria:
Request | Body |
---|---|
POST {{url}}/app/VatAccounts/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Accounting.VatAccount, Winbooks.TORM.OM", |
POST {{url}}/app/Items/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Logistics.Item, Winbooks.TORM.OM", |
POST {{url}}/app/Items/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Logistics.Item, Winbooks.TORM.OM", "Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["FRAME"] } ], "ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ], "MaxResult": 1 } |
POST {{url}}/app/JournalLogs/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Logistics.JournalLog, Winbooks.TORM.OM", |
POST {{url}}/app/Customers/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Customer, Winbooks.TORM.OM", |
POST {{url}}/app/Currencys/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Currency, Winbooks.TORM.OM", |
POST {{url}}/app/PayCodes/Folder/{{folder}}/ExecuteCriteria | { "EntityType": "Winbooks.TORM.OM.Accounting.PayCode, Winbooks.TORM.OM", |
POST {{url}}/app/DocumentHeader/Folder/{{folder}}
The body of the request contains the document to post like this:
{ "$type": "Winbooks.TORM.OM.Logistics.DocumentHeader, Winbooks.TORM.OM", "TotalLevel": 3, "JournalLog_Id": "1104bd81-fac3-498d-bdb1-a74d006d9096", "Customer_Id": "f5e92880-31c0-43af-9348-a85d0117d78b", "Currency_Id": "8d70e1d6-57cf-4bc1-8402-a74d006cd472", "PayCode_Id": "48a7b7ab-0f1b-4420-af2e-a74d006cd9a8", "CurrencyRate": 1, "Number": 2018005, "Date": "/Date(1521028391000)/", "DueDate": "/Date(1521590400000)/", "IsVatIncluded": false, "IsInitial": true, "TotalBase": 500, "TotalVat": 102.38, "TotalToPay": 602.38, "TotalQuantity": 3, "ComputingMethod": 1, "Addressing": { "$type": "Winbooks.TORM.OM.Logistics.DocumentAddressing, Winbooks.TORM.OM", "TotalLevel": 1, "DeliveringAddress_Id": "56e918d4-0cc0-42db-a040-a89b00aa382d", "InvoicingAddress_Id": "56e918d4-0cc0-42db-a040-a89b00aa382d", "PostingAddress_Id": "56e918d4-0cc0-42db-a040-a89b00aa382d", }, "Details": [ { "$type": "Winbooks.TORM.OM.Logistics.DocumentDetail, Winbooks.TORM.OM", "TotalLevel": 2, "RowNumber": 1000, "Quantity": 2, "Amount": 200, "Row": { "$type": "Winbooks.TORM.OM.Logistics.DocumentRow, Winbooks.TORM.OM", "TotalLevel": 1, "Vat_Id": "d939ccde-90ec-45bb-97fe-a74d006cd718", "Item_Id": "41ec5756-f160-4d4f-909c-a8a300c3caea", "Name": "Wheel", "UnitPrice": 100, "DiscountRate": 0, "Comment": "" } }, { "$type": "Winbooks.TORM.OM.Logistics.DocumentDetail, Winbooks.TORM.OM", "TotalLevel": 2, "RowNumber": 2000, "Quantity": 1, "Amount": 300, "Row": { "$type": "Winbooks.TORM.OM.Logistics.DocumentRow, Winbooks.TORM.OM", "TotalLevel": 1, "Vat_Id": "d939ccde-90ec-45bb-97fe-a74d006cd718", "Item_Id": "41ec5756-f160-4d4f-909c-a8a300c3caea", "Name": "Frame", "UnitPrice": 300, "DiscountRate": 0, "Comment": "" } } ] }