It seems this script is running correctly through the playstream when the player account is created: however the currency is not being added/updated at all.
Any suggestions?
namespace My.Function
{
public static class FSKAzureServerGrantCurrencyToPlayer
{
[FunctionName("FSKAzureServerGrantCurrencyToPlayer")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
ILogger log)
{
try
{
// Parse the request body to get 'result'
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
string entityId = data?.EntityId;
string entityType = data?.EntityType;
// Validate entityId and entityType
if (string.IsNullOrEmpty(entityId) || string.IsNullOrEmpty(entityType))
{
return new BadRequestObjectResult("EntityId and EntityType are required.");
}
// Initialize PlayFab SDK
PlayFabSettings.staticSettings.TitleId = "E4875";
PlayFabSettings.staticSettings.DeveloperSecretKey = "REDACTED";
// Create an EntityKey for the entity
EntityKey entityKey = new EntityKey { Id = entityId, Type = entityType };
// Create an AddInventoryItemsRequest and call the PlayFab Economy API to add inventory items asynchronously
var addItemsRequest = new AddInventoryItemsRequest
{
Amount = 1000,
Entity = entityKey,
Item = new InventoryItemReference
{
Id = "269f32a7-9bc7-41a5-b4f9-6c805e0a27c5",
}
};
// Call PlayFab Economy API to add inventory items asynchronously
PlayFabResult<AddInventoryItemsResponse> response = await PlayFabEconomyAPI.AddInventoryItemsAsync(addItemsRequest);
// Handle the response here, e.g., log the IdempotencyId
if (response.Result != null)
{
log.LogInformation($"IdempotencyId: {response.Result.IdempotencyId}");
}
// Return an OkObjectResult or any appropriate response
return new OkObjectResult("Inventory items added successfully.");
}
catch (Exception ex)
{
// Handle any exceptions, e.g., log the error
log.LogError(ex, "Error adding inventory items.");
return new StatusCodeResult(StatusCodes.Status500InternalServerError);
}
}
}
}