Hello!
I’m trying to add an item that I just published into my economy called Bronze Pack (Id: P_BRONZE). This is a lootbox pack with cards which awards the player random low level cards when opened. I added a method to add packs to the player account on CloudCode. This is how the code looks like:
const { InventoryApi } = require("@unity-services/economy-2.3");
const { DataApi } = require("@unity-services/cloud-save-1.2");
module.exports = async ({ params, context, logger }) => {
try {
const { projectId, playerId, accessToken } = context;
const inventoryApi = new InventoryApi({ accessToken });
const cloudSaveApi = new DataApi({ accessToken });
const packId = params.PackId;
logger.debug("params: "+packId);
// Call Economy to add the items into the inventory.
const redeemAddInventoryRequest = { inventoryItemId: packId };
const inventoryApiAddInventoryItemRequest = { addInventoryRequest: redeemAddInventoryRequest, playerId: playerId, projectId: projectId };
logger.debug("request : "+JSON.stringify(inventoryApiAddInventoryItemRequest));
const response = await inventoryApi.addInventoryItem(inventoryApiAddInventoryItemRequest);
logger.debug("response : "+JSON.stringify(response.data));
return response.data.playersInventoryItemId;
} catch (error) {
//transformAndThrowCaughtException(error);
logger.error("error message: "+error.message+ "\nWhole error: "+JSON.stringify(error));
}
}
I call this form within the API with the randomly generated token and it works perfectly, it adds the pack each time and I can validate inside the player management that the player has the packs in his inventory now.
In order to test this with real users, I try to add this to a test menu to gift packs to the currently signed player (signed it through the authentication service).
Each time I try doing it this way, it fails. Here is my c# code of the call being received:
await UnityServices.InitializeAsync();
Dictionary<string, object> args = new Dictionary<string, object>();
args.Add("PackId", "P_BRONZE");
string packPlayerInventoryId = await CloudCodeService.Instance.CallEndpointAsync("TEST_GiftPack", args);
return packPlayerInventoryId;
When I do this, I get the following error message in Cloud Code logs:
error message: Request failed with status code 404
Whole error: {“message”:“Request failed with status code 404”,“name”:“Error”,“stack”:“Error: Request failed with status code 404\n at createError (/home/app/node_modules/@unity-services/economy-2.3/node_modules/axios/lib/core/createError.js:16:15)\n at settle (/home/app/node_modules/@unity-services/economy-2.3/node_modules/axios/lib/core/settle.js:17:12)\n at IncomingMessage.handleStreamEnd (/home/app/node_modules/@unity-services/economy-2.3/node_modules/axios/lib/adapters/http.js:269:11)\n at IncomingMessage.emit (events.js:412:35)\n at endReadableNT (internal/streams/readable.js:1333:12)\n at processTicksAndRejections (internal/process/task_queues.js:82:21)”,“config”:{“url”:“https://economy.services.api.unity.com/v2/projects/6ef7a80f-5d0f-4443-904b-9fb6a1cd5a75/players/uado4xGQm0Xi5CQqSlFFLDlBX45u/inventory",“method”:“post”,“data”:“{“inventoryItemId”:“P_BRONZE”}”,“headers”:{“Accept”:"application/json, text/plain, /”,“Content-Type”:“application/json”,“Authorization”:"Bearer (…)
I tried taking the data on the request and doing a postman call with it, and the error message is a little more meaningful:
{
"type": "problems/basic",
"title": "Not found",
"status": 404,
"detail": "Inventory item not found",
"instance": null,
"code": 10303
}
I am using this bethod somewhere else in a test method to add cards themselves directly, which have numeric based IDs (220, 137, 40, etc…), and these work perfectly, it is only with packs, which have String based IDs (P_BRONZE, P_GOLD, P_PLATINUM, P_WT, etc), that this fails.
Any idea why is this happening? Why is it working with the random PlayerId users on CloudCodeAPI but not the real users on my game client?