addApiTokens
The addApiTokens
function allows you to add a new API
token.
Syntax
writeResult = bApi.addApiTokens(apiTokenObject[] apiTokens);
Attributes
Name | Type | Required | Description |
---|---|---|---|
name |
string | Yes | The name assigned to API token. The name can be used to reference a specific
API token when using the apiToken functions. |
permissions |
int | Yes | The permissions assigned to the API token. An API token can have read, write,
and send permissions. Each permission is assigned an int value. To
assign:
|
active |
boolean | Yes | Whether or not the API token is active. You can always go back and activate or deactivate API tokens at a later time. |
accountId |
boolean | Yes | The account, referenced by ID, that the API token is assigned to. |
PHP Code Example
<?php /** * This script will add an API token with read, write, and send * permissions. The API token will also be made active. * * @copyright Copyright (c) 2011 Bronto Software (http://www.bronto.com) */ $client = new SoapClient('https://api.bronto.com/v4?wsdl', array('trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS)); try { // Add your API token $token = "API TOKEN HERE"; print "logging in\n"; $sessionId = $client->login(array('apiToken' => $token))->return; $session_header = new SoapHeader("http://api.bronto.com/v4", 'sessionHeader', array('sessionId' => $sessionId) ); $client->__setSoapHeaders(array($session_header)); // NOTE the permissions parameter is an int. We use // 7 to assign read, write, and send permissions. // Replace the accountId place holder with a // valid account ID. $apiTokenObject = array('name' => 'Example API Token', 'permissions' => '7', 'active' => true, 'accountId' => 'SOME ACCOUNT ID' ); $write_result = $client->addApiTokens(array($apiTokenObject))->return; // Note we are accessing the results and errors arrays. // Both of these arrays are returned as part of // writeResult object. if ($write_result->errors) { print "There was a problem adding the account:\n"; print_r($write_result->results); } else { print "API Token has been created. Id: " . $write_result->results[0]->id . "\n"; } } catch (Exception $e) { print "uncaught exception\n"; print_r($e); }