# getDirectoryNumbers() for Salesforce Classic

## Usage

Returns the list of phone numbers from the call center's directory. This method is only available in API version 31.0 or later.

## Syntax

```javascript
sforce.interaction.cti.getDirectoryNumbers(isGlobal:boolean, callCenterName:String, (optional) callback:function, (optional) resultSetPage:Integer, (optional) resultSetPageSize:Integer)
```

## Arguments

| Name                | Type     | Description                                                                                                                                                                                                                                                                                                                                                                            |
| ------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `isGlobal`          | boolean  | Set to `true` to return directory numbers from the global call center, or `false` to return directory numbers specific to a call center.                                                                                                                                                                                                                                               |
| `callCenterName`    | string   | Specifies the call center name on which to return directory numbers. If `isGlobal` is `false` and this field is not specified, all directory numbers are returned.                                                                                                                                                                                                                     |
| `callback`          | function | JavaScript method executed when the API method call is completed.                                                                                                                                                                                                                                                                                                                      |
| `resultSetPage`     | integer  | Represents the page number of the list of results to return. This number starts at 0.                                                                                                                                                                                                                                                                                                  |
| `resultSetPageSize` | integer  | Sets the maximum number of phone numbers to retrieve. Defaults to 5000; maximum is 10000. If `hasNext` returns `true` in the `callback`, use this argument with `resultSetPage` to get the next page of results. For example, if `resultSetPageSize` is 5000 and `resultSetPage` is 0, the first 5000 phone numbers are returned; if `resultSetPage` is 1, the next 5000 are returned. |

## Sample Code–JavaScript

```javascript
<html>
<head>
   <script src="https://domain:port/support/api/31.0/interaction.js"></script>
   <script type="text/javascript">
       var callback = function (response) {
           if (response.result) {
                  alert(response.result);
            } else {
                   alert(response.error);
           }
        };

       var isGlobal = false; //Do not return directories from the global call center
       var callCenterName = 'My Call Center'; //Call center name of directory numbers to return

       function getDirectoryNumbers() {
                sforce.interaction.cti.getDirectoryNumbers(isGlobal, callCenterName, callback);
        }
</script>
</head>
<body>
       <button onclick="getDirectoryNumbers();">Get Directory Numbers</button>
</body>
</html>
```

## Response

| Name     | Type   | Description                                                                                                                                                                         |
| -------- | ------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `result` | string | Returns a JSON string that represents the list of phone numbers from the specified call center name. Each phone number element contains a call center name, phone, and description. |
| `error`  | string | If the API call was successful, this variable is undefined. If the API call failed, this variable returns an error message.                                                         |

Example `result`:

```javascript
{ directoryNumbers:
   [ 
      {callCenterName:'Demo Call Center', name:'Sales Cloud', phone:'415-555-1212', description:'Sales Cloud additional number'},
      {callCenterName:'Demo Call Center 2', name:'Service Cloud', phone:'415-555-3434', description:'Service Cloud additional number'},
   ], 
   hasNext: false
} 
```
