---
description: >-
  If you wish to edit a server you must select the server for the Session ID you
  are using to edit. To then edit a different server you must select select that
  server first then edit it.
---

# Selecting A Server To Edit

## Getting A Server's Code

In order to select a server, you need it's code, this is different to it's ID. To get a server's code you must get all servers that the user who's session ID you have and find the ID of the one you want.

The following is code to get all servers that a user has access to:

```javascript
// Dependencies
const CubedCraft = require('cubed-api');

// Account Details
const username = 'ACCOUNT_USERNAME';
const password = 'ACCOUNT_PASSWORD';

// Logging Into The Account
CubedCraft.login(username, password).then(ses => {

    // Getting All Of The User's Servers With Their Session ID
    CubedCraft.getServers(ses).then(servers => {
        console.log(servers);
    })
    
});

```

This code will console log all servers your user has access to. This is a good chance to test your code is working if it can access all the servers.

## Selecting A Server

Now, to select a server to edit or take further dashboard actions on, you must select the server you want using it's code.

To get a server's code use the following code:

```javascript
// Dependencies
const CubedCraft = require('cubed-api');

// Account Details
const username = 'ACCOUNT_USERNAME';
const password = 'ACCOUNT_PASSWORD';

// Server Details
const serverName = 'SERVER_NAME';

// Logging Into The Account
CubedCraft.login(username, password).then(ses => {

    // Getting All Of The User's Servers With Their Session ID
    CubedCraft.getServers(ses).then(servers => {
        const server = servers.find(s => s.name.toLowerCase() === serverName.toLowerCase());
        console.log(server.code);
    })
    
});
```

Now we can use the server code we just got to select the server:

```javascript
// Dependencies
const CubedCraft = require('cubed-api');

// Account Details
const username = 'ACCOUNT_USERNAME';
const password = 'ACCOUNT_PASSWORD';

// Server Details
const serverName = 'SERVER_NAME';

// Logging Into The Account
CubedCraft.login(username, password).then(ses => {

    // Getting All Of The User's Servers With Their Session ID
    CubedCraft.getServers(ses).then(servers => {
        const server = servers.find(s => s.name.toLowerCase() === serverName.toLowerCase());
        CubedCraft.selectServer(ses, server.code);
    })
    
});
```

If you do not get any errors, this code should now select the server you want to edit! Congratulations, you can now send instructions on actions to take for the server.
