UpdateCollection
The UpdateCollection API is used to insert, update, or delete one or more records from an
IDO colleciton.
POST | /update/{ido} |
---|---|
http://localhost/IDORequestService/ido/update/UserNames?efresh=true |
Parameters
Name | In | Required? | Description |
---|---|---|---|
ido | Path | Yes | The name of the IDO collection |
refresh | Query | No | Instructs the system to refresh the collection after the update
is complete Valid values are True or False. |
Headers
Name | Description |
---|---|
Authorization | If the API is called directly, then the Mongoose security token is obtained through a call to the
GetSecurityToken API. If the API is called through the ION API, then a valid OAuth2.0 bearer token is provided by the ION API. |
X-Infor-MongooseConfig | The name of a configuration that is available on the
application server This header is required only when using the Mongoose API through the ION API. |
Request data for an Insert action
{ "Changes": [ { "Action": 1, "ItemId": "PBT=[UserNames]", "Properties": [ { "Name": "Username", "Value": "jdelacruz", "Modified": true, "IsNull": false }, { "Name": "UserDesc", "Value": "Juan Dela Cruz", "Modified": true, "IsNull": false } ], "UpdateLocking": 1 } ] }
Request data for an Update action
{ "Changes": [ { "Action": 2, "ItemId": "PBT=[UserNames] UserNames.DT=[2018-10-02 15:39:02.060] UserNames.ID=[4c9a96d0-ba3c-4de4-8657-6d262f9dcd3f]", "Properties": [ { "Name": "UserDesc", "Value": "John Doe Sr.", "Modified": true, "IsNull": false } ], "UpdateLocking": 1 } ] }
Note: If
"ItemId"
is empty, then the
key properties are used to update the row, and optimistic locking is not used. All key
properties must be included in the request when "ItemId"
is empty. Request data for a Delete action
{ "Changes": [ { "Action": 4, "ItemId": "PBT=[UserNames] UserNames.DT=[2018-12-14 13:52:27.737] u.ID=[265df7d2-802c-4582-a774-a81b675a91a1]" } ] }
Note: If
"ItemId"
is empty, then the
key properties are used to update the row, and optimistic locking is not used. All key
properties must be included in the request when "ItemId"
is empty. Response data for an Insert action
{ "Message": null, "Success": true, "RefreshItems": [ { "Action": 1, "ItemId": "PBT=[UserNames] UserNames.DT=[2019-05-03 13:24:07.080] UserNames.ID=[dd896b24-e1dd-47df-ad4f-f0378243c202]", "ItemNo": 0, "Properties": [ { "IsNestedCollection": false, "IsNull": false, "Modified": false, "Name": "Username", "OriginalValue": null, "Value": "jdelacruz" }, { "IsNestedCollection": false, "IsNull": false, "Modified": false, "Name": "UserDesc", "OriginalValue": null, "Value": "Juan Dela Cruz" } ], "UpdateLocking": 0 } ] }
Response data for an Update action
{ "Message": null, "Success": true, "RefreshItems": [ { "Action": 2, "ItemId": "PBT=[UserNames] UserNames.DT=[2019-05-03 13:24:07.080] UserNames.ID=[dd896b24-e1dd-47df-ad4f-f0378243c202]", "ItemNo": 0, "Properties": [ { "IsNestedCollection": false, "IsNull": false, "Modified": false, "Name": "UserDesc", "OriginalValue": null, "Value": "John Doe Sr." } ], "UpdateLocking": 0 } ] }
Response data for a Delete action
{ "Message": null, "Success": true, "RefreshItems": null }
Example 1 - Insert using UpdateCollection
This example code inserts jdelacruz as a new user.
string json = string.Empty; using ( var client = new HttpClient() ) { string ido = "UserNames"; string requestUrl = $"http://server/IDORequestService/ido/update/{ido}?refresh=true"; // provide token in the Authorization header client.DefaultRequestHeaders.TryAddWithoutValidation( "Authorization", "b/XdI6IQzCviZOGJ0E+002DoKUFOPmVDkwpQDbQj…==" ); UpdateProperty username = new UpdateProperty { Name = "Username", Value = "jdelacruz", IsNull = false, Modified = true }; UpdateProperty userDesc = new UpdateProperty { Name = "UserDesc", Value = "Juan Dela Cruz", IsNull = false, Modified = true }; IDOUpdateItem idoItem = new IDOUpdateItem { Action = UpdateAction.Insert, Properties = new[] { username, userDesc }, ItemId = "PBT=[UserNames]" }; UpdateCollectionRequest request = new UpdateCollectionRequest { Changes = new[] { idoItem } }; // pass the UpdateCollectionRequest as the request data string contentStr = JsonConvert.SerializeObject( request ); // send the post request HttpResponseMessage response = client.PostAsync( requestUrl.ToString(), new StringContent( contentStr, Encoding.UTF8, "application/json" ) ).Result; using ( HttpContent content = response.Content ) { Task<string> result = content.ReadAsStringAsync(); json = result.Result; } }
Example 2 - Update using UpdateCollection
This example code updates the description of user jdoe.
string json = string.Empty; using ( var client = new HttpClient() ) { string ido = "UserNames"; string requestUrl = $"http://server/IDORequestService/ido/update/{ido}?refresh=true"; // provide token in the Authorization header client.DefaultRequestHeaders.TryAddWithoutValidation( "Authorization", "b/XdI6IQzCviZOGJ0E+002DoKUFOPmVDkwpQDbQj…==" ); UpdateProperty userDesc = new UpdateProperty { Name = "UserDesc", Value = "John Doe Sr.", IsNull = false, Modified = true }; IDOUpdateItem idoItem = new IDOUpdateItem { Action = UpdateAction.Update, Properties = new[] { userDesc }, ItemId = "PBT=[UserNames] UserNames.DT=[2019-05-03 13:24:07.080] UserNames.ID=[f33ef708-19bb-4ab9-aade-88a6e8853742]" }; UpdateCollectionRequest request = new UpdateCollectionRequest { Changes = new[] { idoItem } }; // pass the UpdateCollectionRequest as the request data string contentStr = JsonConvert.SerializeObject( request ); // send the post request HttpResponseMessage response = client.PostAsync( requestUrl.ToString(), new StringContent( contentStr, Encoding.UTF8, "application/json" ) ).Result; using ( HttpContent content = response.Content ) { Task<string> result = content.ReadAsStringAsync(); json = result.Result; } }
Example 3 - Delete using UpdateCollection
This example code deletes the user with the given _ItemID property value.
string json = string.Empty; using ( var client = new HttpClient() ) { string ido = "UserNames"; string requestUrl = $"http://server/IDORequestService/ido/update/{ido}?refresh=true"; // provide token in the Authorization header client.DefaultRequestHeaders.TryAddWithoutValidation( "Authorization", "b/XdI6IQzCviZOGJ0E+002DoKUFOPmVDkwpQDbQj…==" ); IDOUpdateItem idoItem = new IDOUpdateItem { Action = UpdateAction.Delete, ItemId = "PBT=[UserNames] UserNames.DT=[2019-05-03 13:24:07.080] UserNames.ID=[dd896b24-e1dd-47df-ad4f-f0378243c202]" }; UpdateCollectionRequest request = new UpdateCollectionRequest { Changes = new[] { idoItem } }; // pass the UpdateCollectionRequest as the request data string contentStr = JsonConvert.SerializeObject( request ); // send the post request HttpResponseMessage response = client.PostAsync( requestUrl.ToString(), new StringContent( contentStr, Encoding.UTF8, "application/json" ) ).Result; using ( HttpContent content = response.Content ) { Task<string> result = content.ReadAsStringAsync(); json = result.Result; } }
You can use these classes to construct the Request Data as demonstrated in the previous code snippets:
public class UpdateCollectionRequest { public IDOUpdateItem[] Changes { get; set; } public bool RefreshAfterSave { get; set; } public string CustomInsert { get; set; } public string CustomUpdate { get; set; } public string CustomDelete { get; set; } } public class IDOUpdateItem { public UpdateAction Action { get; set; } public string ItemId { get; set; } public int ItemNo { get; set; } public UpdateProperty[] Properties { get; set; } public UpdateLocking UpdateLocking { get; set; } } public class UpdateProperty { public string Name { get; set; } public string Value { get; set; } public string OriginalValue { get; set; } public bool Modified { get; set; } public bool IsNull { get; set; } } public enum UpdateAction { Insert = 1, Update = 2, Delete = 4 } public enum UpdateLocking { Row = 0, Property = 1 }