Update single object

This function is used for updating single data object in API- update has the same structure with insert, just change Http verb "POST" into "PUT"

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}

In .NET & C#, client could use WinbooksConverter to create the body content
Update single object


//cosmoCustomer is a result object customer we got from API
//now we modify it and send back to API
cosmoCustomer.Memo = "this is the memo property update for cosmoCustomer" ;
cosmoCustomer.MemoType = MemoType.Green;
// convert to json string
  var jsonString = WinbooksConverter.FromListWinbooksOBjectToJson(lstCustomer, false );

And this is the result we'll include in the body content of request 

{
   "$type": "Winbooks.TORM.OM.Customer, Winbooks.TORM.OM",
   "TotalLevel": 1,
   "Version": 0,
   "Modified": null,
   "ModifiedBy": "00000000-0000-0000-0000-000000000000",
   "Created": null,
   "CreatedBy": "00000000-0000-0000-0000-000000000000",
   "Code": "COSMOSHOP",
   "VatApplicable": 1,
   "LastReminderLevel": 0,
   "LastReminderDate": null,
   "DiscountRate": 0,
   "GlobalDiscountRate": 0,
   "IsPartialDelivery": false,
   "IsPartialDeliveryClosed": false,
   "IsGroupOrderAllowed": false,
   "IsGroupOrderDifferentAgent": false,
   "IsGroupOrderDifferentReference": false,
   "IsGroupDeliveryAllowed": false,
   "IsGroupDeliveryDifferentAgent": false,
   "IsGroupDeliveryDifferentAddress": false,
   "IsGroupDeliveryDifferentReference": false,
   "IsReminderBlocked": false,
   "IsLocked": false,
   "IsHidden": false,
   "MemoType": 1,
   "Memo": "this is the memo property update for cosmoCustomer",
   "DiscountRate2": null,
   "CachedCollection": {},
   "IsBinding": false,
   "IsSetIdByUser": false,
   "Localized": {},
   "Custom": null,
   "UpdatedCollection": {},
   "UpdatedProperties": [
     "Memo",
     "MemoType"
   ],
   "UpdatedValues": [
     "this is the memo property update for cosmoCustomer",
     1
   ]
}

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

b. Using Winbooks.Apis.Services


cosmoCustomer.Memo = "this is the memo property update for cosmoCustomer" ;
cosmoCustomer.MemoType = MemoType.Green;
folderRESTAPIDEMO.UpdateByCode<Customer>(cosmoCustomer, 1);

Update List of Objects

This function is used for updating list of objects in API

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}

In .NET & C#, client could use WinbooksConverter to create the body content


//lstCustomerBE is the result list customer from request 'Get By Criteria'
//now we modify and send back to API
foreach (var customer in lstCustomerBE)
{
     customer.Third.WebSite = "www." + customer.Third.Code.ToLower().Trim( ' ' ) + ".com" ;
}
//convert to jsonstring
var jsonString = WinbooksConverter.FromListWinbooksOBjectToJson(lstCustomerBE, false );

if the request is successful, the result will be as below with status code 200


{
   "Method": "InsertOrUpdateList",
   "ObjectType": "Customer",
   "NumberOfSuccess": 3,
   "NumberOfFail": 0,
   "ListObjectFail": [],
   "ListUrlSuccess": [
     "https://rapi.winbooksonweb.be/app/Customer/ARTHUR/Folder/PARFIWEB_DEMO",
     "https://rapi.winbooksonweb.be/app/Customer/ALPHA/Folder/PARFIWEB_DEMO",
     "https://rapi.winbooksonweb.be/app/Customer/AUBEPINES/Folder/PARFIWEB_DEMO"
   ],
   "ReasonFail": []
}

b. Using Winbooks.Apis.Services


foreach (var customer in lstCustomerBE)
{
     customer.Third.WebSite = "www." + customer.Third.Code.ToLower().Trim( ' ' ) + ".com" ;
}
folderPARFIWEB.UpdateCollection(lstCustomerBE, 2);

Top

  • No labels