Skip to contentSkip to navigationSkip to topbar
On this page

Credentials Resource


(error)

Danger

Programmable Chat has been deprecated and is no longer supported. Instead, we'll be focusing on the next generation of chat: Twilio Conversations. Find out more about the EOL process here(link takes you to an external page).

If you're starting a new project, please visit the Conversations Docs to begin. If you've already built on Programmable Chat, please visit our Migration Guide to learn about how to switch.

(error)

Danger

This is reference documentation for the v1 REST API, which has been deprecated. You should use the current v2 REST API.

The Credential resource represents one credential record for a particular push notifications channel - currently APNS(link takes you to an external page) or GCM(link takes you to an external page). Credentials are different per push vendor and are issued by the vendors themselves. This resource allows you to send Twilio credentials that should be used for push notifications.


Twilio Console

twilio-console page anchor

You can manage the Credentials for use with Programmable Chat using your Twilio console when logged in to the console.


Each credential resource has these properties:

Property nameTypeRequiredDescriptionChild properties
sidSID<CR>

Optional

Not PII

The unique string that we created to identify the Credential resource.

Pattern: ^CR[0-9a-fA-F]{32}$Min length: 34Max length: 34

account_sidSID<AC>

Optional

The SID of the Account that created the Credential resource.

Pattern: ^AC[0-9a-fA-F]{32}$Min length: 34Max length: 34

friendly_namestring

Optional

PII MTL: 30 days

The string that you assigned to describe the resource.


typeenum<string>

Optional

The type of push-notification service the credential is for. Can be: gcm, fcm, or apn.

Possible values:
gcmapnfcm

sandboxstring

Optional

[APN only] Whether to send the credential to sandbox APNs. Can be true to send to sandbox APNs or false to send to production.


date_createdstring<date-time>

Optional

The date and time in GMT when the resource was created specified in RFC 2822(link takes you to an external page) format.


date_updatedstring<date-time>

Optional

The date and time in GMT when the resource was last updated specified in RFC 2822(link takes you to an external page) format.


urlstring<uri>

Optional

The absolute URL of the Credential resource.


1
`GET /Credentials`
2
List all CredentialsLink to code sample: List all Credentials
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function listCredential() {
11
const credentials = await client.chat.v1.credentials.list({ limit: 20 });
12
13
credentials.forEach((c) => console.log(c.sid));
14
}
15
16
listCredential();

Output

1
{
2
"credentials": [
3
{
4
"sid": "CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
5
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
6
"friendly_name": "Test slow create",
7
"type": "apn",
8
"sandbox": "False",
9
"date_created": "2015-10-07T17:50:01Z",
10
"date_updated": "2015-10-07T17:50:01Z",
11
"url": "https://chat.twilio.com/v1/Credentials/CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
12
}
13
],
14
"meta": {
15
"page": 0,
16
"page_size": 50,
17
"first_page_url": "https://chat.twilio.com/v1/Credentials?PageSize=50&Page=0",
18
"previous_page_url": null,
19
"url": "https://chat.twilio.com/v1/Credentials?PageSize=50&Page=0",
20
"next_page_url": null,
21
"key": "credentials"
22
}
23
}

1
`POST /Credentials`
2

Parameters

Request body parameters

request-body-parameters page anchor
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
Typeenum<string>required

The type of push-notification service the credential is for. Can be: gcm, fcm, or apn.

Possible values:
gcmapnfcm

FriendlyNamestring

Optional

A descriptive string that you create to describe the new resource. It can be up to 64 characters long.


Certificatestring

Optional

[APN only] The URL encoded representation of the certificate. For example, -----BEGIN CERTIFICATE----- MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== -----END CERTIFICATE-----


PrivateKeystring

Optional

[APN only] The URL encoded representation of the private key. For example, -----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----END RSA PRIVATE KEY-----


Sandboxboolean

Optional

[APN only] Whether to send the credential to sandbox APNs. Can be true to send to sandbox APNs or false to send to production.


ApiKeystring

Optional

[GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential.


Secretstring

Optional

[FCM only] The Server key of your project from the Firebase console, found under Settings / Cloud messaging.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function createCredential() {
11
const credential = await client.chat.v1.credentials.create({
12
apiKey: "apiKey",
13
friendlyName: "Friendly Name",
14
type: "gcm",
15
});
16
17
console.log(credential.sid);
18
}
19
20
createCredential();

Output

1
{
2
"sid": "CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"friendly_name": "Friendly Name",
5
"type": "gcm",
6
"sandbox": "False",
7
"date_created": "2015-10-07T17:50:01Z",
8
"date_updated": "2015-10-07T17:50:01Z",
9
"url": "https://chat.twilio.com/v1/Credentials/CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
10
}

1
GET /Credentials/{Credential SID}
2
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function fetchCredential() {
11
const credential = await client.chat.v1
12
.credentials("CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.fetch();
14
15
console.log(credential.sid);
16
}
17
18
fetchCredential();

Output

1
{
2
"sid": "CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"friendly_name": "Test slow create",
5
"type": "apn",
6
"sandbox": "False",
7
"date_created": "2015-10-07T17:50:01Z",
8
"date_updated": "2015-10-07T17:50:01Z",
9
"url": "https://chat.twilio.com/v1/Credentials/CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
10
}

1
POST /Credentials/{Credential SID}
2

Parameters

Property nameTypeRequiredPIIDescription
SidSID<CR>required

The Twilio-provided string that uniquely identifies the Credential resource to update.

Pattern: ^CR[0-9a-fA-F]{32}$Min length: 34Max length: 34
Encoding type:application/x-www-form-urlencoded
SchemaExample
Property nameTypeRequiredDescriptionChild properties
FriendlyNamestring

Optional

A descriptive string that you create to describe the resource. It can be up to 64 characters long.


Certificatestring

Optional

[APN only] The URL encoded representation of the certificate. For example, -----BEGIN CERTIFICATE----- MIIFnTCCBIWgAwIBAgIIAjy9H849+E8wDQYJKoZIhvcNAQEFBQAwgZYxCzAJBgNV.....A== -----END CERTIFICATE-----


PrivateKeystring

Optional

[APN only] The URL encoded representation of the private key. For example, -----BEGIN RSA PRIVATE KEY----- MIIEpQIBAAKCAQEAuyf/lNrH9ck8DmNyo3fGgvCI1l9s+cmBY3WIz+cUDqmxiieR. -----END RSA PRIVATE KEY-----


Sandboxboolean

Optional

[APN only] Whether to send the credential to sandbox APNs. Can be true to send to sandbox APNs or false to send to production.


ApiKeystring

Optional

[GCM only] The API key for the project that was obtained from the Google Developer console for your GCM Service application credential.


Secretstring

Optional

[FCM only] The Server key of your project from the Firebase console, found under Settings / Cloud messaging.

1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function updateCredential() {
11
const credential = await client.chat.v1
12
.credentials("CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.update({
14
apiKey: "xxxxxx",
15
friendlyName: "MyCredential",
16
});
17
18
console.log(credential.sid);
19
}
20
21
updateCredential();

Output

1
{
2
"sid": "CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
3
"account_sid": "ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
4
"friendly_name": "MyCredential",
5
"type": "apn",
6
"sandbox": "False",
7
"date_created": "2015-10-07T17:50:01Z",
8
"date_updated": "2015-10-07T17:50:01Z",
9
"url": "https://chat.twilio.com/v1/Credentials/CRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
10
}

1
DELETE /Credentials/{Credential SID}
2
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
const twilio = require("twilio"); // Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
const accountSid = process.env.TWILIO_ACCOUNT_SID;
7
const authToken = process.env.TWILIO_AUTH_TOKEN;
8
const client = twilio(accountSid, authToken);
9
10
async function deleteCredential() {
11
await client.chat.v1
12
.credentials("CRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
13
.remove();
14
}
15
16
deleteCredential();