Loading...
Loading...
Configure account addresses, authentication providers, IP access controls, billing groups, and integration secrets. This skill provides JavaScript SDK examples.
npx skill4agent add team-telnyx/skills telnyx-account-access-javascriptnpm install telnyximport Telnyx from 'telnyx';
const client = new Telnyx({
apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
});clienttry {
const result = await client.messages.send({ to: '+13125550001', from: '+13125550002', text: 'Hello' });
} catch (err) {
if (err instanceof Telnyx.APIConnectionError) {
console.error('Network error — check connectivity and retry');
} else if (err instanceof Telnyx.RateLimitError) {
// 429: rate limited — wait and retry with exponential backoff
const retryAfter = err.headers?.['retry-after'] || 1;
await new Promise(r => setTimeout(r, retryAfter * 1000));
} else if (err instanceof Telnyx.APIError) {
console.error(`API error ${err.status}: ${err.message}`);
if (err.status === 422) {
console.error('Validation error — check required fields and formats');
}
}
}401403404422429for await (const item of result) { ... }GET /access_ip_address// Automatically fetches more pages as needed.
for await (const accessIPAddressResponse of client.accessIPAddress.list()) {
console.log(accessIPAddressResponse.id);
}created_atdescriptionidip_addresssourcestatusupdated_atuser_idPOST /access_ip_addressip_addressdescriptionconst accessIPAddressResponse = await client.accessIPAddress.create({ ip_address: 'ip_address' });
console.log(accessIPAddressResponse.id);created_atdescriptionidip_addresssourcestatusupdated_atuser_idGET /access_ip_address/{access_ip_address_id}const accessIPAddressResponse = await client.accessIPAddress.retrieve('access_ip_address_id');
console.log(accessIPAddressResponse.id);created_atdescriptionidip_addresssourcestatusupdated_atuser_idDELETE /access_ip_address/{access_ip_address_id}const accessIPAddressResponse = await client.accessIPAddress.delete('access_ip_address_id');
console.log(accessIPAddressResponse.id);created_atdescriptionidip_addresssourcestatusupdated_atuser_idGET /addresses// Automatically fetches more pages as needed.
for await (const address of client.addresses.list()) {
console.log(address.id);
}address_bookadministrative_areaboroughbusiness_namecountry_codecreated_atcustomer_referenceextended_addressfirst_nameidlast_namelocalityneighborhoodphone_numberpostal_coderecord_typestreet_addressupdated_atvalidate_addressPOST /addressesfirst_namelast_namebusiness_namestreet_addresslocalitycountry_codeaddress_bookadministrative_areaboroughcustomer_referenceextended_addressneighborhoodphone_numberpostal_codevalidate_addressconst address = await client.addresses.create({
business_name: "Toy-O'Kon",
country_code: 'US',
first_name: 'Alfred',
last_name: 'Foster',
locality: 'Austin',
street_address: '600 Congress Avenue',
});
console.log(address.data);address_bookadministrative_areaboroughbusiness_namecountry_codecreated_atcustomer_referenceextended_addressfirst_nameidlast_namelocalityneighborhoodphone_numberpostal_coderecord_typestreet_addressupdated_atvalidate_addressPOST /addresses/actions/validatecountry_codestreet_addresspostal_codeadministrative_areaextended_addresslocalityconst response = await client.addresses.actions.validate({
country_code: 'US',
postal_code: '78701',
street_address: '600 Congress Avenue',
});
console.log(response.data);errorsrecord_typeresultsuggestedGET /addresses/{id}const address = await client.addresses.retrieve('550e8400-e29b-41d4-a716-446655440000');
console.log(address.data);address_bookadministrative_areaboroughbusiness_namecountry_codecreated_atcustomer_referenceextended_addressfirst_nameidlast_namelocalityneighborhoodphone_numberpostal_coderecord_typestreet_addressupdated_atvalidate_addressDELETE /addresses/{id}const address = await client.addresses.delete('550e8400-e29b-41d4-a716-446655440000');
console.log(address.data);address_bookadministrative_areaboroughbusiness_namecountry_codecreated_atcustomer_referenceextended_addressfirst_nameidlast_namelocalityneighborhoodphone_numberpostal_coderecord_typestreet_addressupdated_atvalidate_addressPOST /addresses/{id}/actions/accept_suggestionsidconst response = await client.addresses.actions.acceptSuggestions(
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
);
console.log(response.data);acceptedidrecord_typeGET /authentication_providers// Automatically fetches more pages as needed.
for await (const authenticationProvider of client.authenticationProviders.list()) {
console.log(authenticationProvider.id);
}activated_atactivecreated_atidnameorganization_idrecord_typesettingsshort_nameupdated_atPOST /authentication_providersnameshort_namesettingsactivesettings_urlconst authenticationProvider = await client.authenticationProviders.create({
name: 'Okta',
settings: {
idp_cert_fingerprint: '13:38:C7:BB:C9:FF:4A:70:38:3A:E3:D9:5C:CD:DB:2E:50:1E:80:A7',
idp_entity_id: 'https://myorg.myidp.com/saml/metadata',
idp_sso_target_url: 'https://myorg.myidp.com/trust/saml2/http-post/sso',
},
short_name: 'myorg',
});
console.log(authenticationProvider.data);activated_atactivecreated_atidnameorganization_idrecord_typesettingsshort_nameupdated_atGET /authentication_providers/{id}const authenticationProvider = await client.authenticationProviders.retrieve('550e8400-e29b-41d4-a716-446655440000');
console.log(authenticationProvider.data);activated_atactivecreated_atidnameorganization_idrecord_typesettingsshort_nameupdated_atPATCH /authentication_providers/{id}activenamesettingssettings_urlshort_nameconst authenticationProvider = await client.authenticationProviders.update('id', {
active: true,
name: 'Okta',
settings: {
idp_entity_id: 'https://myorg.myidp.com/saml/metadata',
idp_sso_target_url: 'https://myorg.myidp.com/trust/saml2/http-post/sso',
idp_cert_fingerprint: '13:38:C7:BB:C9:FF:4A:70:38:3A:E3:D9:5C:CD:DB:2E:50:1E:80:A7',
idp_cert_fingerprint_algorithm: 'sha1',
},
short_name: 'myorg',
});
console.log(authenticationProvider.data);activated_atactivecreated_atidnameorganization_idrecord_typesettingsshort_nameupdated_atDELETE /authentication_providers/{id}const authenticationProvider = await client.authenticationProviders.delete('550e8400-e29b-41d4-a716-446655440000');
console.log(authenticationProvider.data);activated_atactivecreated_atidnameorganization_idrecord_typesettingsshort_nameupdated_atGET /billing_groups// Automatically fetches more pages as needed.
for await (const billingGroup of client.billingGroups.list()) {
console.log(billingGroup.id);
}created_atdeleted_atidnameorganization_idrecord_typeupdated_atPOST /billing_groupsnameconst billingGroup = await client.billingGroups.create({ name: 'my-resource' });
console.log(billingGroup.data);created_atdeleted_atidnameorganization_idrecord_typeupdated_atGET /billing_groups/{id}const billingGroup = await client.billingGroups.retrieve('f5586561-8ff0-4291-a0ac-84fe544797bd');
console.log(billingGroup.data);created_atdeleted_atidnameorganization_idrecord_typeupdated_atPATCH /billing_groups/{id}nameconst billingGroup = await client.billingGroups.update('f5586561-8ff0-4291-a0ac-84fe544797bd', {
name: 'my-resource',
});
console.log(billingGroup.data);created_atdeleted_atidnameorganization_idrecord_typeupdated_atDELETE /billing_groups/{id}const billingGroup = await client.billingGroups.delete('f5586561-8ff0-4291-a0ac-84fe544797bd');
console.log(billingGroup.data);created_atdeleted_atidnameorganization_idrecord_typeupdated_atGET /integration_secrets// Automatically fetches more pages as needed.
for await (const integrationSecret of client.integrationSecrets.list()) {
console.log(integrationSecret.id);
}created_atididentifierrecord_typeupdated_atPOST /integration_secretsidentifiertypepasswordtokenusernameconst integrationSecret = await client.integrationSecrets.create({
identifier: 'my_secret',
type: 'bearer',
token: 'my_secret_value',
});
console.log(integrationSecret.data);created_atididentifierrecord_typeupdated_atDELETE /integration_secrets/{id}await client.integrationSecrets.delete('550e8400-e29b-41d4-a716-446655440000');POST /telephony_credentials/{id}/tokenconst response = await client.telephonyCredentials.createToken('550e8400-e29b-41d4-a716-446655440000');
console.log(response);