How to assign users to world id using V3 APIs for each episode?

We would like to run models at once using the same world and we have tried it using V2 APIs which is already, has been using to run models one by one but it is not able to run all models at once using the same world id thus there are v3 APIs having episode concept to run all models using different episode with same world id. How to assign users to that world id using V3 APIs for each episode?

This answer assumes you’re using Epicenter v3 Libraries, which you can install to your project via npm install epicenter-libs. If you’d rather use the libraries directly, you can do so by adding it as a script in your HTML like:
<script src="https://forio.com/tools/js-libs/3.18.0/epicenter.js" charset="utf-8"></script>

Note that if you do the direct linking, you won’t be able to use the import strategy used below (eg import { runAdapter } from 'epicenter-libs';) and instead you’ll need to use something like const { runAdapter } = epicenter;

Starting on the facilitator side, you’ll need a few things. First, we’ll add the Personas. This is essentially telling Epicenter how we want our worlds to be structured. I’m assuming every user is the same role, but you could set it up so each user has their own role within the world, just add more objects to the array being sent in (eg [{ role: 'role1', minimum: 1 }, { role: 'role2', minimum: 1 }])

import { worldAdapter, SCOPE_BOUNDARY } from 'epicenter-libs';

worldAdapter.setPersonas([{ role: 'user', minimum: 1 }], {
    scopeBoundary: SCOPE_BOUNDARY.group,
    scopeKey: epicenterGroupKey,
});

Next, we’ll create the episodes. In the example below, I’m using the model names as the episode names to easily track them.

import { episodeAdapter } from 'epicenter-libs';
const episode = await episodeAdapter.create('episodeNameHere', epicenterGroupName);

Now that you have an episode, we’ll need to create worlds.

const world = await worldAdapter.create({
    groupName: epicenterGroupName,
    episodeName: 'episodeNameHere',
});

Once you have your world created, we’ll need to assign users to it. Note keepEmptyWorld means that if you move a user from World001 to World002 leaving World001 empty, Epicenter will delete it for you or leave it around depending on how you set this flag. The objective is MINIMUM, MARGINAL, or MAXIMUM and have different use cases. In this case, I’m assuming I can have more than one user per role, so I’m using MAXIMUM

const assignments = await worldAdapter.editAssignments(
    { [world.worldKey]: [{ userKey: user.userKey, role: 'user' }] },
    {
        groupName: epicenterGroupName
        episodeName: 'episodeNameHere',
        keepEmptyWorld: false,
        objective: 'MAXIMUM',
    }
);

Now you have your personas, an episode, and a world all set up with a user assigned to the world. If needed, you can do this for multiple episodes and worlds.

Hope that helps!