---
title: "2. Insert Data and Update Data"
canonical: "https://help.winbooks.be/space/DEV/3211294/2.%20Insert%20Data%20and%20Update%20Data"
format: markdown
---
To Insert and Update data we have 2 ways

> Macro (legacy-content)

* Standard json format: is available for all client, especially client not using our support library like Apis - light and easy to use  
**Non-standard json format: is still in json format but have some additional special properties processed by our DAL or OM, this json is usually generated by our lib : Winbooks.Serializer . Suitable for client using our DAL and OM dll to perform complicated task

## A. Insert Single Object

This function is used for inserting single data object in API

### a. Using HTTP

|  |
| --- |
| `URL: { REST API Host } / app / { Winbooks OM } / { Code } / Folder/ { FolderCode } `  
`Method : POST`  
`Header : `  
`   ` `Authorization : Bearer {access_token}`  
`   ` `Content-Type : application/json`  
`Body content : {object in json format}` |

 

<span style="color: #000000">In .NET, for making body content, client could use WinbooksConverter </span>  
**Serialize by WinbooksConverter**

|  |  |
| --- | --- |
|  | `// insert Customer`  
`Customer newCustomer = ``new` `Customer();`  
`newCustomer.MemoType = MemoType.Green;`  
`newCustomer.Code = ``"ALICE"` `;`  
`newCustomer.Memo = ``"this memo is for customer Alice Wilder"` `;`  
`//CREATE MANDATORY OBJECT`  
`newCustomer.Third = ``new` `Third();`  
`newCustomer.Third.Code = ``"ALICE"` `;`  
`newCustomer.Third.Name = ``"Alice Wilder"` `;`  
`newCustomer.Third.WebSite = ``"`[www.alice-wilder.com](http://www.alice-wilder.com)`"` `;`  
`string` `jsonString = WinbooksConverter.FromWinbooksObjectToJson(newCustomer, ``false` `);` |

And this is the result we'll include in the body content of request ,  
**non-standard json format**

|  |
| --- |
| `{`  
`  ` `"$type": "Winbooks.TORM.OM.Customer, Winbooks.TORM.OM",`  
`  ` `"$isShowId": false,`  
`  ` `"TotalLevel": 2,`  
`  ` `"Code": "ALICE",`  
`  ` `"Version": 0,`  
`  ` `"Localized": {},`  
`  ` `"MemoType":"1",`  
`  ` `"Third": {`  
`    ` `"$type": "Winbooks.TORM.OM.Third, Winbooks.TORM.OM",`  
`    ` `"TotalLevel": 1,`  
`    ` `"UpdatedProperties": [`  
`      ` `"Code",`  
`      ` `"Name",`  
`      ` `"WebSite"`  
`    ` `],`  
`    ` `"UpdatedValues": [`  
`      ` `"ALICE",`  
`      ` `"Alice Wilder",`  
`      ` `"`[www.alice-wilder.com](http://www.alice-wilder.com)`"`  
`    ` `]`  
`  ` `},`  
`  ` `"UpdatedTypes": [],`  
`  ` `"UpdatedProperties": [`  
`    ` `"MemoType",`  
`    ` `"Code",`  
`    ` `"Memo",`  
`    ` `"Third_Id"`  
`  ` `],`  
`  ` `"UpdatedValues": [`  
`    ` `1,`  
`    ` `"ALICE",`  
`    ` `"this memo is for customer Alice Wilder",`  
`    ` `"00000000-0000-0000-0000-000000000000"`  
`  ` `],`  
`}` |

or if client not using our serializer , we could make it more simple   
**standard json**

|  |
| --- |
| `{`  
` ` `"Code": "ALICE",`  
` ` `"MemoType":"1",`  
` ` `"Memo": "this memo is for customer Alice Wilder",`  
` ` `"Third": `  
`    ` `{`  
`        ` `"Code":"ALICE",`  
`        ` `"Name":"Alice Wilder",`  
`        ` `"Website":"`[www.alice-wilder.com](http://www.alice-wilder.com)`"`  
`    ` `}`  
`}` |

<span style="color: #ff0000">**Note :</span><span style="color: #ff0000"> </span>For standard json in single object,  <span style="color: #222222">json string could contain Id/code of object . If not contains, we will get id/code from url</span>

<span style="color: #222222">             With multiple objects, each json member in json array must have id/code</span>

If the request is successful, the result will be as below with status code 201.

|  |
| --- |
| `"href":" `[https://rapi.winbooksonweb.be/app/Customer/VLADIMIR/Folder/PARFIWEB_DEMO"](https://rapi.winbooksonweb.be/app/Customer/VLADIMIR/Folder/PARFIWEB_DEMO) |

### b. Using Winbooks.Apis.Services

|  |
| --- |
| `//CREATE SINGLE CUSTOMER`  
`Customer newCustomer = ``new` `Customer();`  
`newCustomer.MemoType = MemoType.Green;`  
`newCustomer.Code = ``"ALICE"` `;`  
`newCustomer.Memo = ``"this memo is for customer Alice Wilder"` `;`  
`//CREATE MANDATORY OBJECT`  
`newCustomer.Third = ``new` `Third();`  
`newCustomer.Third.Code = ``"ALICE"` `;`  
`newCustomer.Third.Name = ``"Alice Wilder"` `;`  
`newCustomer.Third.WebSite = ``"`[www.alice-wilder.com](http://www.alice-wilder.com)`"` `;`  
`//INSERT NEW CUSTOMER TO FOLDER PARFIWEB`  
`bool isInsertSuccess = folderPARFIWEB.Insert<Customer>(newCustomer, ``2` `);` |

## B. Insert List of Objects

This function is used to Insert or Update a list of objects.

### a. Using HTTP

|  |
| --- |
| `URL : { REST API Host } / app / { Winbooks OMS } / Folder / { FolderCode }`  
`Method : POST`  
`Header :`  
`  ` `Authorization : Bearer {access_token}`  
`  ` `Content-Type : application/json`  
`Body Content: { list of object need to be inserted in json format}` |

<span style="color: #000000">In .NET & C#, client could use WinbooksConverter to create the body content</span>  
**Convert list of Winbooks objects to JSON**

|  |
| --- |
| `   ` `foreach` `(var customerName ``in` `customerNames)`  
`{`  
`    ` `Customer cust = ``new` `Customer();`  
`    ` `cust.Code = customerName.Trim(` `' '` `).ToUpper();`  
`    ` `cust.MemoType = MemoType.Green;`  
`    ` `cust.Memo = ``"this is the memo of "` `+ customerName;`  
`    ` `cust.Third = ``new` `Third();`  
`    ` `cust.Third.Name = customerName;`  
`    ` `cust.Third.Code = customerName.Trim(` `' '` `).ToUpper();`  
`    ` `cust.Third.WebSite = ``"www."` `+ customerName.Trim(` `' '` `).ToLower();`  
`    ` `lstNewCustomers.Add(cust);`  
`}`  
`    ` `// convert to json string`  
`    ` `var jsonString = WinbooksConverter.FromListWinbooksOBjectToJson(lstCustomer, ``false` `);` |

If client not using our converter, standard json string will be like this  
**Standard json with multiple object**

|  |
| --- |
| `[`  
`    ` `{`  
`        ` `"Code":"COSMOSHOP",`  
`        ` `"MemoType":"1",`  
`        ` `"Memo":"this is the memo of cosmoshop",`  
`        ` `"IsLocked":"false",`  
`        ` `"Third":`  
`            ` `{`  
`                ` `"Code":"COSMOSHOP",`  
`                ` `"Name":"Cosmopolitan shop",`  
`                ` `"Website":"`[www.cosmopolitanshop.com](http://www.cosmopolitanshop.com)`"`  
`            ` `}`  
`    ` `},`  
`    ` `{`  
`        ` `"Code":"MELODIE",`  
`        ` `"MemoType":"1",`  
`        ` `"Memo":"this is the memo of melodie",`  
`        ` `"IsLocked":"false",`  
`        ` `"Third":`  
`            ` `{`  
`                ` `"Code":"MELODIE",`  
`                ` `"Name":"Melodie shop",`  
`                ` `"Website":"`[www.melodieshop.com](http://www.melodieshop.com)`"`  
`            ` `}`  
`    ` `}`  
`]` |

<span style="color: #222222">**Note :With multiple objects, each json member in json array must have id/code</span>

### b. Using Winbooks.Apis.Services

  
**Insert list Of Customers**

|  |
| --- |
| `for` `(` `int` `i = 0; i < arrayStrings.Count(); i++)`  
`{`  
`    ` `Customer cust = ``new` `Customer();`  
`    ` `cust.Code = arrayStrings[i];`  
`    ` `cust.IsGroupDeliveryAllowed = ``true` `;`  
`    ` `cust.IsHidden = ``false` `;`  
`    ` `cust.IsLocked = ``false` `;`  
`    ` `cust.Third = ``new` `Third();`  
`    ` `cust.Third.Code = arrayStrings[i];`  
`    ` `cust.Third.Addresses = ``new` `List<Address>();`  
`    ` `lstCustomer.Add(cust);`  
`}`  
`// Insert List of Customer`  
`EntitiesServices folderRESTAPIDEMO = ``new` `EntitiesServices(userCredential, ``"PARIWEB_DEMO"` `);`  
`folderRESTAPIDEMO.InsertCollection(lstCustomer);` |