Force Leave App

If users are in the app and we force them to leave, all their data is still intact so that when they rejoin, it’s seamless?

There are different ways of forcing users to leave the app.

When you are doing this from the app itself you need to specify keepData: true, like this.
journey.leaveApp({ keepData: true });

If you are doing it using the “sessions” API (which is part of the Backend API), then you need to use the correct API call, either “Re-authenticate session” or “Lock User” (Please note that for using Lock User you will need to specify wipe:false to keep the data on the device)

When I want to lock all users via api, what’s the code for the bulk lock?

You can use the sessions API to lock a specific user. You can find the more details in the docs here. There isn’t currently a way to bulk lock all users using the API.

Wont there be a api limit if I’m trying to lock ±200 users?

@sisa-zaza To avoid API limits, you can use batch operations. Find the documentation here.

To use batch operations with locking multiple users, the body of the request would be:

{
  "operations": [
      {
        "method": "users/lock",
        "user_id": "...",
        "wipe": true/false
      },
     {
        "method": "users/lock",
        "user_id": "...",
        "wipe": true/false
      },
     ...
  ]
}

Hi Molly,

Thank you for your response. So on CC task I can do the following?

var operations = ;

var object_method = {};

for(var i = 0; i < external_data.length; i++){

object_method = {

“method”: ‘users/lock’,

“user_id”: external_data[i].id.toString(),

" wipe": false

}

operations.push(object_method);

}

var lock_user = {

“operations”: operations

}

var new_options = {

method: ‘POST’,

headers: {

‘Content-Type’: ‘application/json’,

‘Authorization’: 'Bearer ’ + ‘O:3STWU7JMCe2PVR8rT4uZLfpztvxsgZQyzGDZ3orRHw3u’

}

}

var post_response = await fetch(‘https://run-eu.journeyapps.com/api/v4/’ + ‘5ccc21b059023f38788ac5c3/’ + lock_user,new_options);

@sisa-zaza This is very close, however, there are a couple things that you would need to change here:

  1. Include the lock_user in your new_options variable within the body:
var new_options = {
        method: 'POST',
        headers: {
          "Content-Type": 'application/json',
         "Authorization": 'Bearer ' + 'O:3STWU7JMCe2PVR8rT4uZLfpztvxsgZQyzGDZ3orRHw3u'
        },
        body: JSON.stringify(lock_user)
    }
  1. Update your fetch url to include /batch.json and your new_options variable
... fetch('https://run-eu.journeyapps.com/api/v4/' + '5ccc21b059023f38788ac5c3/batch.json', new_options)

With these changes, this code should work in CC. Let me know if you run into any issues.