Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Solved
  • Unsolved
  • Users
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Darkly)
  • No Skin
Collapse
brainCloud Forums
  1. Home
  2. General
  3. Method to access "other user" items

Method to access "other user" items

Scheduled Pinned Locked Moved Solved General
itemsusers
2 Posts 2 Posters 2.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexandru
    wrote on last edited by
    #1

    Hello,

    Is there a way to access the items another user has in his inventory?
    We are looking for something similar to https://getbraincloud.com/apidocs/apiref/#capi-useritems-getuseritem but for another user.

    1 Reply Last reply
    1
    • Paul WinterhalderP Offline
      Paul WinterhalderP Offline
      Paul Winterhalder
      brainCloudAdmin
      wrote on last edited by Paul Winterhalder
      #2

      Hi Claudiu,

      It's possible to do this using cloud script... you just need to impersonate the other user...

      Here's an example script that does this - caveat, it only returns the first page of user items.

      Create the script, and set it's test parameters to:

      {
        "profileId": "www-xxx-yyy-zzzz-123456"
      }
      

      (Note - you'll of course want to replace profileId with an id of a user that you want to test with.)

      And here's the code...

      var response = {};
      
      // We need to impersonate another user to make this call
      var otherSession = bridge.getSessionForProfile( data.profileId );
      var otherUserItemsProxy = bridge.getUserItemsServiceProxy( otherSession );
      
      // Now, request the page of items from that proxy
      var context = {
        "pagination": {
          "rowsPerPage": 50,
          "pageNumber": 1
        },
        "searchCriteria": {},
        "sortCriteria": {
          "createdAt": 1
        }
      };    
      var includeDef = true;
      
      var itemResult = otherUserItemsProxy.getUserItemsPage( context, includeDef );
      
      if (( itemResult.status == 200) && ( itemResult.data.results.count > 0 )) {
          response.items = itemResult.data.results.items;
      } else {
          response.items = [];
      }
      
      response;
      

      For convenience I've attached an export of the script. You can import this script into your app from the Design | Cloud Code | Scripts screen.

      Hope that helps!

      Paul.

      RetrieveAnotherUsersItems.ccjs

      1 Reply Last reply
      0

      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

      With your input, this post could be even better 💗

      Register Login
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Solved
      • Unsolved
      • Users