---
title: "Examples using the Rest API with the invoicing Documents"
canonical: "https://help.winbooks.be/space/DEV/3211367/Examples%20using%20the%20Rest%20API%20with%20the%20invoicing%20Documents"
format: markdown
---
## 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

**<span style="color: #339966">GET </span>**<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/Third/BEBOP/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">?MaxLevel=2</span>

<span style="color: #505050">The property </span>**<span style="color: #505050">DefaultAddress.Id</span>**<span style="color: #505050"> give you this Id (56e918d4-0cc0-42db-a040-a89b00aa382d).</span>

<span style="color: #505050">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.</span>

### <span style="color: #505050">Make a query</span>

<span style="color: #505050">It's </span><u><span style="color: #505050">really more efficient</span></u><span style="color: #505050"> to use queries and especially queries with projection to get just what we need. This can be done with the </span>**<span style="color: #505050">/ExecuteCriteria</span>**<span style="color: #505050"> suffixe.</span>

**<span style="color: #ff6600">POST </span>**<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/Addresss/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span>

<span style="color: #505050">The body of the request contains the criteria corresponding to this query in .NET:</span>

|  |
| --- |
| `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"``);` |


<span style="color: #505050">Body for the ExecuteCriteria in JSON: </span>

`{
   "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"
]
`


### <span style="color: #505050">Post the DocumentHeader (using the friendly code properties)</span>

**<span style="color: #ff6600">POST </span>**<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/DocumentHeader/Folder/</span><span style="color: #ff8f4e">{{folder}}</span>

<span style="color: #000000">The body of the request contains the document to post like this:</span>

`{
    "$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"
}`


### <span style="color: #505050">Post the DocumentHeader (using the Id's)</span>

<span style="color: #000000">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.</span>

<span style="color: #000000">First, we have to retrieve the Id's:</span>

| **Request** | **Id** |
| --- | --- |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/Vat/21/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | d939ccde-90ec-45bb-97fe-a74d006cd718 |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/Item/WHEEL/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | 9976a7a9-f27b-4d5d-a414-a8a300c385ad |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/Item/FRAME/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | 41ec5756-f160-4d4f-909c-a8a300c3caea |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/JournalLog/ORDER/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | 1104bd81-fac3-498d-bdb1-a74d006d9096 |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/Customer/BEBOP/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | f5e92880-31c0-43af-9348-a85d0117d78b |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/Currency/EUR/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | 8d70e1d6-57cf-4bc1-8402-a74d006cd472 |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/PayCode/7/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | 48a7b7ab-0f1b-4420-af2e-a74d006cd9a8 |

<span style="color: #000000">Or really more efficiently via the ExecuteCriteria:</span>

| **Request** | **Body** |
| --- | --- |
| <span style="color: #ff6600">**POST**</span>** **<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">VatAccounts</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Accounting.VatAccount**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**21**"] } ],  
"ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ],  
"MaxResult": 1 } |
| <span style="color: #ff6600">**POST**</span>** **<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">Items</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Logistics.Item**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**WHEEL**"] } ],  
"ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ],  
"MaxResult": 1 } |
| <span style="color: #ff6600">**POST**</span>**<span style="color: #ff6600"> </span>**<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">Items</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Logistics.Item**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**FRAME**"] } ],  
"ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ],  
"MaxResult": 1 } |
| <span style="color: #ff6600">**POST**</span>** **<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">JournalLogs</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Logistics.JournalLog**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**ORDER**"] } ],  
"ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ],  
"MaxResult": 1 } |
| <span style="color: #ff6600">**POST**</span>**<span style="color: #ff8f4e"> </span>**<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">Customers</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Customer**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**BEBOP**"] } ],  
"ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ],  
"MaxResult": 1 } |
| <span style="color: #ff6600">**POST**</span>** **<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">Currencys</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Currency**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**EUR**"] } ],  
"ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ],  
"MaxResult": 1 } |
| <span style="color: #ff6600">**POST**</span>** **<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">PayCodes</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Accounting.PayCode**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**7**"] } ],  
"ProjectionsList": [ {"PropertyName": "Id", "Operator": 22} ],  
"MaxResult": 1 } |


**<span style="color: #ff6600">POST </span>**<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/DocumentHeader/Folder/</span><span style="color: #ff8f4e">{{folder}}</span>

<span style="color: #000000">The body of the request contains the document to post like this:</span>

`{
    "$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": ""
            }
        }
    ]
}`