question

evan0424 avatar image
evan0424 asked

Can Revisions(Legacy) access Inventory(V2)?

then, how to use Inventory/AddInventoryItems?

I tried this, but error comes cause unauthorized. plz help!

 handlers.TestItem = function (args, context)
 {
    
     var headers = {
         "X-EntityToken": context.GetEntityToken
     };
        
     var body = {
         // Entity: args.Entity,
         Item: args.Item,
         Amount: args.Amount,
     };
    
     var url = "https://titleId.playfabapi.com/Inventory/AddInventoryItems";
     var content = JSON.stringify(body);
     var httpMethod = "Post";
     var contentType = "application/json";
    
     log.info(context);
    
     // The pre-defined http object makes synchronous HTTP requests
     var response = http.request(url, httpMethod, content, contentType, headers);
     return { responseContent: response };
 }

,then, how to use Inventory/AddInventoryItems?

I tried this. but a error comes cause unauthorize.

 handlers.TestItem = function (args, context)
 {
    
     var headers = {
         "X-EntityToken": context.GetEntityToken
     };
        
     var body = {
         // Entity: args.Entity,
         Item: args.Item,
         Amount: args.Amount,
     };
    
     var url = "https://titleId.playfabapi.com/Inventory/AddInventoryItems";
     var content = JSON.stringify(body);
     var httpMethod = "Post";
     var contentType = "application/json";
    
     log.info(context);
    
     // The pre-defined http object makes synchronous HTTP requests
     var response = http.request(url, httpMethod, content, contentType, headers);
     return { responseContent: response };
 }

plz help!

Player Inventory
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Xiao Zha avatar image
Xiao Zha answered

There is no such property called "GetEntityToken" in the context parameter and there is a keyword "economy" in Legacy CouldScript that allows you to access the Economy V2 API. Below is a code example for your reference.

 handlers.Test=function(args,context)
 {
     var test=economy.AddInventoryItems({
         Entity: args.Entity,
         Item:{
             Id:"xxxxx"
         },
         Amount:1
     });
     log.debug(test);
     return test;
 }
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.