CreateEntity
Method creates a new entity on the server.
Service | Operation |
---|---|
globalEntity | CREATE |
Method Parameters
Parameter | Description |
---|---|
entityType | The entity type as defined by the user |
timeToLive | Sets expiry time for entity in milliseconds if > 0 |
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. |
jsonEntityData | The entity's data object |
Usage
http://localhost:3000
- C#
- C++
- Objective-C
- Java
- JavaScript
- Dart
- Cloud Code
- Raw
string entityType = "address";
ACL acl = new ACL(ACL.Access.None);
string jsonEntityAcl = "{\"other\":1}";
string jsonEntityData = "{\"street\":\"1309 Carling\"}";
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.GlobalEntityService.CreateEntity(entityType, timeToLive, jsonEntityAcl, jsonEntityData, successCallback, failureCallback);
const char *entityType = "address";
int timeToLive = -1;
const char *jsonEntityAcl = "{\"other\":1}";
const char *jsonEntityData = "{\"street\":\"1309 Carling\"}";
_bc->getGlobalEntityService()->createEntity(entityType, timeToLive, jsonEntityAcl, jsonEntityData, this);
NSString *entityType = @"address";
int timeToLive = -1;
NSString *jsonEntityAcl = [ACL getAclJson:ReadWrite];
NSString *jsonEntityData = @"{\"street\":\"1309 Carling\"}";
BCCompletionBlock successBlock; // define callback
BCErrorCompletionBlock failureBlock; // define callback
[[_bc globalEntityService] createEntity:entityType
timeToLive:timeToLive
jsonEntityAcl:jsonEntityAcl
jsonEntityData:jsonEntityData
completionBlock:successBlock
errorCompletionBlock:failureBlock
cbObject:nil];
String entityType = "address";
int timeToLive = -1;
String jsonEntityAcl = "{\"other\":1}";
String jsonEntityData = "{\"street\":\"1309 Carling\"}";
this; // implements IServerCallback
_bc.getGlobalEntityService().createEntity(entityType, timeToLive, jsonEntityAcl, jsonEntityData, 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 = "address";
var timeToLive = -1;
var jsonEntityAcl = {
"other": 1
};
var jsonEntityData = {
"street": "1309 Carling"
};
_bc.globalEntity.createEntity(entityType, timeToLive, jsonEntityAcl, jsonEntityData, result =>
{
var status = result.status;
console.log(status + " : " + JSON.stringify(result, null, 2));
});
var entityType = "address";
var timeToLive = -1;
var jsonEntityAcl = {
"other": 1
};
var jsonEntityData = {
"street": "1309 Carling"
};
ServerResponse result = await _bc.globalEntityService.createEntity(entityType:entityType, timeToLive:timeToLive, jsonEntityAcl:jsonEntityAcl, jsonEntityData:jsonEntityData);
if (result.statusCode == 200) {
print("Success");
} else {
print("Failed ${result.error['status_message'] ?? result.error}");
}
var entityType = "address";
var timeToLive = -1;
var jsonEntityAcl = {
"other": 1
};
var jsonEntityData = {
"street": "1309 Carling"
};
var globalEntityProxy = bridge.getGlobalEntityServiceProxy();
var postResult = globalEntityProxy.createEntity(entityType, timeToLive, jsonEntityAcl, jsonEntityData);
if (postResult.status == 200) {
// Success!
}
{
"service": "globalEntity",
"operation": "CREATE",
"data": {
"entityType": "address",
"timeToLive": -1,
"acl": {
"other": 1
},
"data": {
"street": "1309 Carling"
}
}
}
JSON Response
{
"data": {
"gameId": "12832",
"entityId": "e75f4304-2af3-42eb-8e10-ba419cd224d1",
"ownerId": "3b284d94-cbdf-43a7-9239-34d45aa27720",
"entityType": "address",
"entityIndexedId": null,
"version": 1,
"acl": {
"other": 1
},
"expiresAt": 9223372036854776000,
"timeToLive": -1,
"createdAt": 1582645167040,
"updatedAt": 1582645167040
},
"status": 200
}