Skip to main content
All CollectionsFeatures and APIs
How do I use PostMan to test S2S API Calls?
How do I use PostMan to test S2S API Calls?

Making server-to-server requests from brainCloud

Paul Winterhalder avatar
Written by Paul Winterhalder
Updated over 2 months ago

brainCloud support two varieties of S2S calls: with and without a sessionId.

When making an S2S API call without a sessionId, a disposable sessionId will be quickly generated and thrown away after the call. Note - you charged for this additional authentication call. This is quick and convenient for testing, but not the recommended approach.

To use the session-based protocol, you will need to first authenticate to get a sessionId to use. You will then you will carry over that sessionId in future calls, while incrementing the packetId value.

[Note - session-base S2S messages support bundling multiple API within the single request. This can be very useful in some circumstances.]

Overall, the session-based S2S protocol is recommended for production applications, because it eliminates the redundant creation of disposable sessions. It performs better and costs you less!

Installing PostMan

Pretty simple:

Using PostMan as S2S (No SessionId)

  1. Add a new Request

  2. Set the request to be a Post

  3. Select Body | Text | JSON (application/json)

  4. Select raw and add your JSON (see below example)

  5. Select Send

  6. View the Response

{
   //Set the ID of Your App
   "appId": "12142",
   //Set the Name of the Server being used.
   //Server Name?
   //  Scroll down to find explanation
   "serverName": "EXAMPLE_SERVER",
   //Set the secret of your server
   "serverSecret": "b221c2a4-8df9-4937-8f9b-a95e4f71d5b6",
   //Set the service being called. Not all services are available in an S2S context, see the API Ref for a full list.
   //http://getbraincloud.com/apidocs/apiref/#s2s
   "service": "script",
   //Set the operation being ran
   //Service and Operation?
   //  Scroll down to find explanation
   "operation": "RUN",
   //Set the data being used by this API call
   "data": {
       "scriptName": "AddNums",
       "scriptData": {
           "a": 3,
           "b": 4
       }
   }
}

Using PostMan as S2S (With Session)

First, we need to Authenticate to get a SessionId

  1. Add a new Request

  2. Set the request to be a Post

  3. Select Body | Text | JSON (application/json)

  4. Select raw and add your JSON  (see below example)

  5. View the response, and save that sessionId.

{
   //Set the ID of Your App
   "appId": "12142",
   //Set the Name of the Server being used.
   //App Server Name?
   //  Scroll down to find explanation
   "serverName": "EXAMPLE_SERVER",
   //Set the secret of your server
   "serverSecret": "b221c2a4-8df9-4937-8f9b-a95e4f71d5b6",\
   //Set the service and operation to 'authenticationV2' and 'AUTHENTICATE'
   "service": "authenticationV2",
   "operation": "AUTHENTICATE",
   //Set the appId, serverName, and serverSecret in this data package
   "data": {
       "appId": "12142",
       "serverName": "EXAMPLE_SERVER",
       "serverSecret": "b221c2a4-8df9-4937-8f9b-a95e4f71d5b6"
   }
}

Now, we can make an API Call with that sessionId

  1. Add a new Request

  2. Set the request to be a Post

  3. Select Body | Text | JSON (application/json)

  4. Select raw and add your JSON  (see below example)

  5. View the response.

Remember to increment the packetId for each request you make with this sessionId.

{
  //Set the sessionId from earlier
  "sessionId":"df5gelac0mhrpht31fagtgatoe",
  //Set the packetId. You need to increment the packetId by one with each request,
  "packetId":1,
  //Attach the API Calls you are making in a list
  "messages":[
     {
        "service":"globalEntity",
        "operation":"CREATE_SYSTEM_ENTITY",
        "data":{
           "entityType":"address",
           "timeToLive":null,
           "acl":{
              "other":1
           },
           "data":{
              "street":"1309 Carling"
           }
        }
     }
  ]
}

Server Name?

The Server name is created on the brainCloud dashboard. This allows brainCloud to know that your PostMan connections are from a server you own and aren't malicious connections.

1. Go to your brainCloud App project. https://portal.braincloudservers.com

2. Design | Cloud Code | S2S Config. Click  the "New Server" button

3. Give your Server a name, like EXAMPLE_SERVER

4. Can leave the ranges blank. This will make all IP ranges acceptable

5. Hit Save, and you will now have the server secret

The brainCloud dashboard is also where you will find the appId. Design | Core App Info | Application IDs.

Service and Operation?

Our API Calls referenced in the API Ref (https://docs.braincloudservers.com/api/s2s/) are mapped to Services and Operations on the server

Operations are how the API calls appear server side. 

Services are what group of brainCloud that the Operations are affecting. ie. An UPDATE operation has little meaning without know if its affects Stats, Achievements, Multiplayer, or other service contexts.

Only the API Calls in the S2S section can be used for S2S calls.

Did this answer your question?