UpdateSingleton
Updates the singleton owned by the user for the specified custom entity type on the server, creating the singleton if it does not exist. This operation results in the owned singleton's data being completely replaced by the passed in JSON object.
Service | Operation |
---|---|
customEntity | UPDATE_SINGLETON |
Method Parameters
Parameter | Description |
---|---|
entityType | The type of custom entity singleton to create/update. Custom entity type must have option isOwned set to true. |
version | Version of the custom entity singleton being updated. |
dataJson | The singleton entity's custom field data, as JSON. |
acl | The singleton entity's Access Control List as an object. A null ACL implies default permissions which make the entity readable by others. |
timeToLive | The duration of time, in milliseconds, the singleton custom entity should live before being expired. Null indicates never expires. Value of -1 indicates no change for updates. |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string entityType = "athletes";
int version = 1;
string dataJson = "{\"firstName\":\"Super\",\"surName\":\"Star\",\"position\":\"defense\",\"goals\":3,\"assists\":5}";
string acl = "{\"other\":1}";
int timeToLive = null;
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.CustomEntityService.UpdateSingleton(entityType, version, dataJson, acl, timeToLive, successCallback, failureCallback);
const char *entityType = "athletes";
int version = 1;
const char *dataJson = "{\"firstName\":\"Super\",\"surName\":\"Star\",\"position\":\"defense\",\"goals\":3,\"assists\":5}";
const char *acl = "{\"other\":1}";
int timeToLive = null;
_bc->getCustomEntityService()->updateSingleton(entityType, version, dataJson, acl, timeToLive, this);
NSString *entityType = @"athletes";
int version = 1;
NSString *dataJson = "{\"firstName\":\"Super\",\"surName\":\"Star\",\"position\":\"defense\",\"goals\":3,\"assists\":5}";
NSString *acl = "{\"other\":1}";
int timeToLive = null;
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc customEntityService] updateSingleton:entityType
version:version
dataJson:dataJson
acl:acl
timeToLive:timeToLive
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String entityType = "athletes";
int version = 1;
String dataJson = "{\"firstName\":\"Super\",\"surName\":\"Star\",\"position\":\"defense\",\"goals\":3,\"assists\":5}";
String acl = "{\"other\":1}";
int timeToLive = null;
this; // implements IServerCallback
_bc.getCustomEntityService().updateSingleton(entityType, version, dataJson, acl, timeToLive, 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 entityType = "athletes";
var version = 1;
var dataJson = {
"firstName": "Super",
"surName": "Star",
"position": "forward",
"goals": 3,
"assists": 5
};
var acl = {
"other": 1
};
var timeToLive = null;
_bc.customEntity.updateSingleton(entityType, version, dataJson, acl, timeToLive, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var entityType = "athletes";
var version = 1;
var dataJson = {
"firstName": "Super",
"surName": "Star",
"position": "forward",
"goals": 3,
"assists": 5
};
var acl = {
"other": 1
};
var timeToLive = null;
ServerResponse result = await _bc.customEntityService.updateSingleton(entityType:entityType, version:version, dataJson:dataJson, acl:acl, timeToLive:timeToLive);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var entityType = "athletes";
var version = 1;
var dataJson = {
"firstName": "Super",
"surName": "Star",
"position": "defense",
"goals": 3,
"assists": 5
};
var acl = {
"other": 1
};
var timeToLive = null;
var customEntityProxy = bridge.getCustomEntityServiceProxy();
var postResult = customEntityProxy.updateSingleton(entityType, version, dataJson, acl, timeToLive);
if (postResult.status == 200) {
// Success!
}
{
"service": "customEntity",
"operation": "UPDATE_SINGLETON",
"data": {
"entityType": "athletes",
"version": 1,
"dataJson": {
"firstName": "Super",
"surName": "Star",
"position": "defense",
"goals": 3,
"assists": 5
},
"acl": {
"other": 1
},
"timeToLive": null
}
}
JSON Response
{
"data": {
"timeToLive": null,
"version": 2,
"expiresAt": null,
"updatedAt": 1591820239028
},
"status": 200
}