-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated subaccounts doc and examples
- Loading branch information
Showing
5 changed files
with
96 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,53 @@ | ||
# Subaccounts | ||
|
||
This library provides easy access to the [Subaccounts](https://www.sparkpost.com/api#/reference/subaccounts) Resource. | ||
This library provides easy access to the [Subaccounts](https://developers.sparkpost.com/api/subaccounts) Resource. | ||
|
||
## Methods | ||
* **all(callback)** | ||
* **all([callback]) → `{Promise}`**<br /> | ||
List a summary of all subaccounts. | ||
* `callback` - executed after task is completed. **required** | ||
* `callback` - executed after task is completed if provided* | ||
* standard `callback(err, data)` | ||
* `err` - any error that occurred | ||
* `data` - full response from request client | ||
* **find(subaccountId, callback)** | ||
* **find(id[, callback]) → `{Promise}`**<br /> | ||
Retrieve details about a specified subaccount by its id | ||
* `subaccountId` - the id of the subaccount you want to look up **required** | ||
* `id` - the id of the subaccount you want to look up **required** | ||
* `callback` - see all function | ||
* **create(options, callback)** | ||
* **create(subaccount[, callback]) → `{Promise}`**<br /> | ||
Create a new subaccount | ||
* `options.name` - user-friendly name **required** | ||
* `options.keyLabel` - user-friendly identifier for subaccount API key **required** | ||
* `options.keyGrants` - list of grants to give the subaccount API key **required** | ||
* `options.keyValidIps` - list of IPs the subaccount may be used from | ||
* `options.ipPool` - id of the default IP pool assigned to subaccount's transmissions | ||
* `subaccount` - an object of [subaccount attributes](https://developers.sparkpost.com/api/subaccounts#header-request-body-attributes) **required** | ||
* `callback` - see all function | ||
* **update(options, callback)** | ||
* **update(subaccount[, callback]) → `{Promise}`**<br /> | ||
Updates an existing subaccount | ||
* `options.subaccountId` - the id of the subaccount you want to update **required** | ||
* `options.name` - user-friendly name | ||
* `options.status` - status of the subaccount | ||
* `options.ipPool` - id of the default IP pool assigned to subaccount's transmissions | ||
* `callback` - see all function | ||
* `subaccount` - an object of [updatable subaccount attributes](https://developers.sparkpost.com/api/subaccounts#header-request-body-attributes-1) **required** | ||
* `subaccount.id` - the id of the subaccount you want to update **required** | ||
|
||
*callback is optional because all methods return a Promise. | ||
|
||
## Examples | ||
|
||
```js | ||
var SparkPost = require('sparkpost'); | ||
var client = new SparkPost('YOUR_API_KEY'); | ||
```javascript | ||
var SparkPost = require('sparkpost') | ||
, client = new SparkPost('YOUR_API_KEY'); | ||
|
||
client.subaccounts.all() | ||
.then(data => { | ||
console.log('Congrats you can use our client library!'); | ||
console.log(data); | ||
}) | ||
.catch(err => { | ||
console.log('Whoops! Something went wrong'); | ||
console.log(err); | ||
}); | ||
|
||
// Using a callback | ||
client.subaccounts.all(function(err, data) { | ||
if(err) { | ||
if (err) { | ||
console.log('Whoops! Something went wrong'); | ||
console.log(err); | ||
return; | ||
} else { | ||
console.log('Congrats you can use our client library!'); | ||
console.log(data); | ||
} | ||
|
||
console.log(data); | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters