Skip to main content
All CollectionsPortal-X Pages
Design | Integrations | Peer Services
Design | Integrations | Peer Services

sharing resources and functionality across several apps

Jason Liang avatar
Written by Jason Liang
Updated over 8 months ago

Peer services are designed for sharing data and functionality across several apps. A typical scenario would involve a single application, known as the peer service app, storing all tokens purchased by a user for use across various other applications, referred to as peer client apps.

Set Peer App

  • If you did not set up an app as a peer service, on the Design | Core App Info | Peer Publish page, click [Edit] to start modifying the peer information. For more information about these options, refer to the docs of Peer Publish.

    • Check the Enable As Peer Service option.

    • Select an option for service visibility.

    • Select an option for API usage.

    • On the Directory tab, add readable information on your peer.

  • On the Design | Marketplace | Virtual Currencies page, add a virtual currency by clicking the plus icon and setting a name for the currency.

  • Switch to another app, on the Design | Integrations | Peer Services page, you will find the peer app service shown in the More Services section. Choose the peer service you just created by clicking the plus icon to connect it.

  • From the Configure Peer Service dialog, enter a name in the Service code input box. (This value is used when making API calls against the peer via the current app.) Then click Save.

  • You will find your selected peer service is listed under the Connected Services section now.

  • Go to Design | Marketplace | Virtual Currencies page, the peer app currencies should show up under the Peer Currencies section

Test the Peer App Data

  • Call AttachPeerProfile() API of Identity service with the peer service code (here is "peerLib") and the current login user credential as parameters on the API Explorer page. A new user will be generated within the peer service app and associated with the current user in the peer client app.

  • From the User | Summary | User Summary page, you will find the peer relation shows up under the Relations list.

  • Back to the API Explorer page, call AwardPeerCurrency() API from VirtualCurrency service, set parameters virtual currency id with the name you defined on the peer service app, a value for the amount, and the peer service code.

  • Switch to the peer service app (here is "peerLib"). From the User | Summary | User Summary page, you will find the peer client info (the virtual currency you added from the peer client app and the relations to the client apps under the Relations section).

Test with hooks

  • Go to the peer service app Design | Core App Info | Peer Publish page, and link a script for Validate Config from the Hooks tab.

    • Note: this createAsset script will take some parameters and create a custom entity as below.

    • "use strict";

      function main() {

      var response = {};
      // set a key valid for the config validation
      response.valid = true;

      bridge.logDebugJson("Script inputs", data);

      var templateResc = {
      "assetType": "templateType",
      "assetUrl": "templateUrl",
      "assetDesc": "tempalteDesc"
      };

      //if calling from peer app, system auto add peerConfig parameter
      var addpeerConfig = Object.assign({"peerConfig":"someconfigs"},templateResc);

      var checkkeymessage = null;

      //loop input json key, throw error if any invalid key is found
      for (var x in data){
      if(!addpeerConfig.hasOwnProperty(x)){
      checkkeymessage = "invalid key found: "+ x;
      response.createResult = checkkeymessage;
      break;
      }
      }

      if(!checkkeymessage){
      //count entities number before creating a new custom entity, the count number determines the assetId
      var entityType = "asset";
      var context = {
      "pagination": {
      "rowsPerPage": 100,
      "pageNumber": 1
      },
      "searchCriteria": {
      },
      "sortCriteria": {
      "createdAt": 1
      }
      }

      var customEntityProxy = bridge.getCustomEntityServiceProxy();

      var postResult = customEntityProxy.sysGetEntityPage(entityType, context);
      if (postResult.status == 200) {

      //create a new entity with designed jsonFields
      var assetId = postResult.data.results.count + 1;

      //allow user put zero or the complete three parameter to template
      var dataJson = Object.assign({"assetId": assetId.toString()}, templateResc, data);
      var acl = {
      "other": 2
      };
      var timeToLive = null;
      var owner = null;

      var createResult = customEntityProxy.sysCreateEntity(entityType, dataJson, acl, timeToLive, owner);
      if (createResult.status == 200) {
      // Success!
      response.createResult = "asset with id "+assetId+" is successfully created!"
      }
      }
      }
      return response;
      }

      main();

  • Switch to a peer client app on the User | Summary | User Summary page, and select one user who has attached a peer identity to the peer service app, then hit Login As User to set for the portal's current user.

  • Go to Design | Integrations | Peer Services page, find this peer app server, and click Edit of Actions from the Connected Services list. Enter the script-required data as parameters to the Configuration Parameters box. Click Validate.

  • Switch back to the peer service app on the page Global | Global Data | Custom Entities, you should find the custom entity listed here. It was created from a peer client app at the above validating step.

Call Peer scripts

  • Navigate to the peer service app on page Design| Cloud Code | Scripts, Create or import some scripts, and make sure Peer is checked under Client Callable of the script editor dialogue.

  • Then your peer client app users who have attached peer identity associated with this peer service app can call this script by running the RunPeerScript() API of ScriptService service with the peer service code.

    For an additional illustration of using peer service, please refer to the following article for further informations.

Did this answer your question?