UpdateEntity
Method updates an entity on the server. This operation results in the entity data being completely replaced by the passed in JSON string.
This method is affected by versioning. See the versioning documentation for more information.
Service | Operation |
---|---|
entity | UPDATE |
Method Parameters
Parameter | Description |
---|---|
entityId | The id of the entity to update |
entityType | The entity type as defined by the user |
jsonEntityData | The entity's data object |
jsonEntityAcl | The entity's Access Control List as object. A null ACL implies default permissions which make the entity readable/writeable by only the user. |
version | The version of the entity to update. Use -1 to indicate the newest version |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string entityId = "someEntityId";
string entityType = "address";
string jsonEntityData = "{\"street\":\"1309 Carling Avenue, Ottawa, ON\"}";
string jsonEntityAcl = "{\"other\":0}";
int version = -1;
SuccessCallback successCallback = (response, cbObject) =>
{
Debug.Log(string.Format("Success | {0}", response));
};
FailureCallback failureCallback = (status, code, error, cbObject) =>
{
Debug.Log(string.Format("Failed | {0} {1} {2}", status, code, error));
};
_bc.EntityService.UpdateEntity(entityId, entityType, jsonEntityData, jsonEntityAcl, version, successCallback, failureCallback);
const char *entityId = "someEntityId";
const char *entityType = "address";
const char *jsonEntityData = "{\"street\":\"1309 Carling Avenue, Ottawa, ON\"}";
const char *jsonEntityAcl = "{\"other\":0}";
int version = -1;
_bc->getEntityService()->updateEntity(entityId, entityType, jsonEntityData, jsonEntityAcl, version, this);
NSString *entityId = @"someEntityId";
NSString *entityType = @"address";
NSString *jsonEntityData = @"{\"street\":\"1309 Carling Avenue, Ottawa, ON\"}";
NSString *jsonEntityAcl = @"{\"other\":0}";
int version = -1;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc entityService] updateEntity:entityId
entityType:entityType
jsonEntityData:jsonEntityData
jsonEntityAcl:jsonEntityAcl
version:version
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String entityId = "someEntityId";
String entityType = "address";
String jsonEntityData = "{\"street\":\"1309 Carling Avenue, Ottawa, ON\"}";
String jsonEntityAcl = "{\"other\":0}";
int version = -1;
this; // implements IServerCallback
_bc.getEntityService().updateEntity(entityId, entityType, jsonEntityData, jsonEntityAcl, version, this);
public void serverCallback(ServiceName serviceName, ServiceOperation serviceOperation, JSONObject jsonData)
{
System.out.print(String.format("Success | %s", jsonData.toString()));
}
public void serverError(ServiceName serviceName, ServiceOperation serviceOperation, int statusCode, int reasonCode, String jsonError)
{
System.out.print(String.format("Failed | %d %d %s", statusCode, reasonCode, jsonError.toString()));
}
var entityId = "someEntityId";
var entityType = "address";
var jsonEntityData = {
"street": "1309 Carling Avenue, Ottawa, ON"
};
var jsonEntityAcl = {
"other": 0
};
var version = -1;
_bc.entity.updateEntity(entityId, entityType, jsonEntityData, jsonEntityAcl, version, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var entityId = "someEntityId";
var entityType = "address";
var jsonEntityData = {
"street": "1309 Carling Avenue, Ottawa, ON"
};
var jsonEntityAcl = {
"other": 0
};
var version = -1;
ServerResponse result = await _bc.entityService.updateEntity(entityId:entityId, entityType:entityType, jsonEntityData:jsonEntityData, jsonEntityAcl:jsonEntityAcl, version:version);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var entityId = "someEntityId";
var entityType = "address";
var jsonEntityData = {
"street": "1309 Carling Avenue, Ottawa, ON"
};
var jsonEntityAcl = {
"other": 0
};
var version = -1;
var entityProxy = bridge.getEntityServiceProxy();
var postResult = entityProxy.updateEntity(entityId, entityType, jsonEntityData, jsonEntityAcl, version);
if (postResult.status == 200) {
// Success!
}
{
"service": "entity",
"operation": "UPDATE",
"data": {
"entityId": "someEntityId",
"entityType": "address",
"data": {
"street": "1309 Carling Avenue, Ottawa, ON"
},
"acl": {
"other": 0
},
"version": -1
}
}
JSON Response
{
"status": 200,
"data": {
"entityId": "113db68a-48ad-4fc9-9f44-5fd36fc6445f",
"entityType": "person",
"version": 1,
"data": {
"name": "john",
"age": 30
},
"acl": {
"other": 0
},
"createdAt": 1395943044322,
"updatedAt": 1395943044322
}
}
Common Error Code
Status Codes
Code | Name | Description |
---|---|---|
40332 | UPDATE_FAILED | An update operation failed. Used for entities, global entities, and updates on the user. |