---
title: "Examples using the Rest API with Customer"
canonical: "https://help.winbooks.be/space/DEV/3211354/Examples%20using%20the%20Rest%20API%20with%20Customer"
format: markdown
---
# Posting a new customer in C# with the Winbooks.Apis.Services


```csharp
        private static Guid GetId(ICriteria criteria, string type, string code)
        {
            criteria.Add(Condition.Eq("Code", code))
                .SetProjection(Projections.Property("Id"))
                .SetMaxResults(1);
            Newtonsoft.Json.Linq.JArray id = _folder.GetFilterAll(criteria.JsonCriteriaSerialize(), type);
            Guid guid = id == null ? Guid.Empty : Guid.Parse(id[0].ToString());
            return guid;
        }


        private static void PostNewCustomer()
        {
            Guid country_id = GetId(new CountryDAO().CreateCriteria(), "Country", "BE");
            Guid civility_id = GetId(new CivilityDAO().CreateCriteria(), "Civility", "NV");
            Guid language_id = GetId(new LanguageDAO().CreateCriteria(), "Language", "nl");
            Guid currency_id = GetId(new CurrencyDAO().CreateCriteria(), "Currency", "EUR");
            Guid vat_id = GetId(new VatDAO().CreateCriteria(), "Vat", "21");
            Guid customerCategory_id = GetId(new CustomerCategoryDAO().CreateCriteria(), "CustomerCategory", "BIG");
            Guid defaultAccount_Id = GetId(new GLAccountDAO().CreateCriteria(), "GLAccount", "700000");
            Guid centralAccount_Id = GetId(new GLAccountDAO().CreateCriteria(), "GLAccount", "400000");
            Guid payCode_id = GetId(new PayCodeDAO().CreateCriteria(), "PayCode", "7");

            Customer cust = new Customer();
            cust.Code = "WBG3";
            cust.VatApplicable = VatApplicable.Subject;
            cust.Vat_Id = vat_id;
            cust.CustomerCategory_Id = customerCategory_id;
            cust.GLAccount_Id = defaultAccount_Id;
            cust.GLAccount2_Id = centralAccount_Id;
            cust.PayCode_Id = payCode_id;

            cust.Third = new Third();
            cust.Third.Code = "WBG3";
            cust.Third.Name = "WINBOOKS GROUP 3";
            cust.Third.ThirdCivility_Id = civility_id;
            cust.Third.Language_Id = language_id;
            cust.Third.Currency_Id = currency_id;
            cust.Third.VatCountry_Id = country_id;
            cust.Third.VatNumber = "0000000394";
            cust.Third.Addresses = new List<Address>();

            Address adr = new Address();
            adr.Address1 = "330 Lemonierlaan";
            adr.Address2 = "";
            adr.PhoneNo = "+3223456789";
            adr.Country_Id = country_id;
            adr.Zip = "2000";
            adr.Town = "Antwerpen";
            adr.IsDelivering = true;
            adr.IsDeliveringDefault = true;
            adr.IsInvoicing = true;
            adr.IsInvoicingDefault = true;
            adr.IsPosting = true;
            adr.IsPostingDefault = true;

            cust.Third.Addresses.Add(adr);

            _folder.Insert<Customer>(cust, 3, false);

       }
```


# Posting a new customer (with the friendly code properties)

We suggest avoiding the usage of the friendly code properties when you post a list of Customers. You should get the Id of the entities before. 

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

<span style="color: #000000">The body of the request </span>**<span style="color: #000000">for version <= 2.4 of WinBooks on Web</span>**<span style="color: #000000"> will be like this:</span>

```
{
   "$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 body **for version >= 2.5 of WinBooks On Web** looks like this:

```
{
    "$type": "Winbooks.TORM.OM.Customer, Winbooks.TORM.OM",
    "TotalLevel": 5,
    "Code": "WB6",
    "VatApplicable": 1,
    "Third": {
        "$type": "Winbooks.TORM.OM.Third, Winbooks.TORM.OM",
	    "TotalLevel": 4,
        "Code": "WB6",
        "Name": "Customer WB6",
        "VatNumber": "0000000394",
        "Addresses": [
            {
                "$type": "Winbooks.TORM.OM.Third_Address, Winbooks.TORM.OM",
			    "TotalLevel": 3,
                "IsDelivering": true,
                "IsDeliveringDefault": true,
                "IsPosting": true,
                "IsPostingDefault": true,
                "IsInvoicing": true,
                "IsInvoicingDefault": true,
                "Index": 0,
                "Address": {
                    "$type": "Winbooks.TORM.OM.Address, Winbooks.TORM.OM",
					"TotalLevel": 2,
                    "Address1": "330 Lemonierlaan (WB6)",
                    "Town": "Antwerpen",
                    "Zip": "2000",
                    "PhoneNo": "+3223456789",
					"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.

<span style="color: #000000">Do not use the DefaultAddress entity which does not support the posting.</span>

## <span style="color: #000000">Posting a new Customer (with 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 customers using the same country, civility, language, currency, vat, category, default account, central account or payment term (PayCode).</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/</span>**<span style="color: #505050">Country/BE</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | 4bb898f0-21ba-4ea9-9c35-a74d006cd473 |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">Civility/NV</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | 9bc5b8f4-3682-46c6-ac84-a74d006cd9ad |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">Language/en</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | 4b2d0fa7-ecf7-4883-9e04-a89d00bcd216 |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">Currency/EUR</span>**<span style="color: #505050">/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/</span>**<span style="color: #505050">Vat/21</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span>  
or<br>**<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">VatAccount/21</span>**<span style="color: #505050">/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/</span>**<span style="color: #505050">CustomerCategory/BIG</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | c3613c92-d081-4a94-a245-a8b3005d2391 |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">GLAccount/700000</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | c61c5554-0803-4286-9315-a74d006cd5aa |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">GLAccount/400000</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span> | 023a99d0-f1e5-45c8-b902-a74d006cd5a8 |
| **<span style="color: #99cc00">GET</span>**<span style="color: #99cc00"> </span><span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/</span>**<span style="color: #505050">PayCode/7</span>**<span style="color: #505050">/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">Countrys</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Countrys**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**BE**"] } ],  
"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">Civilitys</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**ThirdCivility**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**NV**"] } ],  
"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">Languages</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Language**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**en**"] } ],  
"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">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">GLAccounts</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Accounting.GLAccount**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**700000**"] } ],  
"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">GLAccounts</span>**<span style="color: #505050">/Folder/</span><span style="color: #ff8f4e">{{folder}}</span><span style="color: #505050">/ExecuteCriteria</span> | { "EntityType": "Winbooks.TORM.OM.**Accounting.GLAccount**, Winbooks.TORM.OM",  
"Conditions": [ {"Operator": 0, "PropertyName": "Code", "Values": ["**4****00000**"] } ],  
"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: #000000">To post the customer, the body will be this one</span>**<span style="color: #000000"> for version <= 2.4</span>**<span style="color: #000000">:</span>

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


<span style="color: #000000">And this one </span>**<span style="color: #000000">for version >= 2.5</span>**<span style="color: #000000">:</span>

```
{
    "$type": "Winbooks.TORM.OM.Customer, Winbooks.TORM.OM",
	"TotalLevel": 4,
    "Code": "WB5",
    "Vat_Id": "1d625e47-4871-450b-91c8-9f9400b4ca36",
    "GLAccount_Id": "5633a32d-c312-4e19-9e6b-9f9400b4c691",
    "GLAccount2_Id": "d2647e20-8267-4703-90c0-9f9400b4c67a",
    "PayCode_Id": "f6a39f52-a79d-4758-933a-9f9400b4d059",
    "VatApplicable": 1,
    "Code": "WB5",
    "Third": {
        "$type": "Winbooks.TORM.OM.Third, Winbooks.TORM.OM",
    	"TotalLevel": 3,
        "Code": "WB5",
        "ThirdCivility_Id": "5f4964b8-00f2-464f-a01d-9f9400b4d0ce",
        "VatCountry_Id": "8f8a337e-b483-4c30-b6ed-9f9400b4c553",
        "Language_Id": "5dc36906-5d31-4ff9-b20c-9f9400b4c5df",
        "Currency_Id": "2b790e84-f9f5-4ff6-b775-9f9400b4c54e",
        "Name": "Customer WB5",
        "VatNumber": "0000000394",
        "Code": "WB5",
        "Addresses": [
            {
                "$type": "Winbooks.TORM.OM.Third_Address, Winbooks.TORM.OM",
				"TotalLevel": 2,
                "IsDelivering": true,
                "IsDeliveringDefault": true,
                "IsPosting": true,
                "IsPostingDefault": true,
                "IsInvoicing": true,
                "IsInvoicingDefault": true,
                "Index": 0,
                "Address": {
                    "$type": "Winbooks.TORM.OM.Address, Winbooks.TORM.OM",
					"TotalLevel": 1,
                    "Country_Id": "8f8a337e-b483-4c30-b6ed-9f9400b4c553",
                    "Address1": "330 Lemonierlaan (WB5)",
                    "Town": "Antwerpen",
                    "Zip": "2000",
                    "PhoneNo": "+3223456789"
                }
            }
        ]
    }
}
```

## <span style="color: #000000">Check if a Customer exists</span>

<span style="color: #000000">The best is to use the ExecuteCriteria.</span>

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

<span style="color: #505050">The body of the request:</span>


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

## <span style="color: #000000">Update a Customer</span>

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.

<span style="color: #3366ff">**PUT**</span>**<span style="color: #ff6600"> </span>**<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/Customer/TEST2/Folder/</span><span style="color: #ff8f4e">{{folder}}</span>

<span style="color: #000000">The body to update the Customer and the Third is:</span>

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

#### For version <= 2.4 of WinBooks on Web

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");`  
`if (addressid == null)`  
`   Tools.Log(" no address for BEBOP");`  
`else`  
`   Tools.Log(" address_id = " + addressid[0].ToString());`  


The corresponding http request is this one:

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

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": [
            "BEBOP"
         ],
      }
   ],
   "ProjectionsList": [
      {
         "PropertyName": "Id",
         "Operator": 22
      }
   ],
}
```


#### For version >= 2.5 of WinBooks on Web

This is the .NET query to do that (with the Winbooks.Apis.Service.dll):

`ICriteria criteria = new Third_AddressDAO().CreateCriteria()`  
`   .CreateAlias("address", typeof(Address), Address.Names.Id, Third_Address.Names.Address_Id)`  
`   .CreateAlias("third", typeof(Third), Third.Names.Id, Third_Address.Names.Third_Id)`  
`   .Add(Condition.Eq("third." + Third.Names.Code, "BEBOP"))`  
`   .Add(Condition.Eq(Third_Address.Names.IsInvoicingDefault, true))`  
`   .SetProjection(Projections.Property("address." + Address.Names.Id));`  
`Newtonsoft.Json.Linq.JArray addressid = _folder.GetFilterAll(criteria.JsonCriteriaSerialize(), "Third_Address");`  
`if (addressid == null)`  
`   Tools.Log(" no address for BEBOP");`  
`else`  
`   Tools.Log(" address_id = " + addressid[0].ToString());`

The corresponding http request is this one:

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

with the following JSON body:

```
{
    "EntityType": "Winbooks.TORM.OM.Third_Address, Winbooks.TORM.OM",
    "IsCustomization": false,
    "Alias": "this",
    "Association": {
        "address": {
            "AliasName": "address",
            "Type": "Winbooks.TORM.OM.Address, Winbooks.TORM.OM",
            "JoinType": 1,
            "LeftProperty": "Id",
            "RightProperty": "Address_Id"
        },
        "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"
            ]
        },
        {
            "Operator": 0,
            "PropertyName": "IsInvoicingDefault",
            "OtherPropertyName": "",
            "Values": [
                true
            ]
        }
    ],
   "Havings": [],
    "ProjectionsList": [
        {
            "PropertyName": "address.Id",
            "Operator": 22
        }
    ],
    "Orders": [],
    "Params": {},
    "FirstResult": -1,
    "MaxResult": -1,
    "ResultState": 0,
    "TimeOutSeconds": 0
}
```


#### 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.

**<span style="color: #3366ff">PUT </span>**<span style="color: #ff8f4e">{{url}}</span><span style="color: #505050">/app/Address/Folder/</span><span style="color: #ff8f4e">{{folder}}</span>

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

`}`