Node.js SDK
anchorFeatures
anchor- Manage Webex user accounts
- Send messages and file attachments
- Create spaces and manage space memberships
- FedRAMP environment support. See usage README
anchorGetting Started Guide
anchorIn this example, we'll use Node.js to create a simple project that will post a message to a room.
If you're interested in integrating Webex functionality in your front-end web applications, check out the Browser SDK.
Overview
- Create a Webex space
- Post a Message
Requirements
Step 1: Create the Project Directory
cd /my/project/directory
npm init
You’ll be prompted to answer a few simple questions, but typically the defaults are just fine.
Step 2: Install the JavaScript SDK
Now, install webex
:
npm install --save webex
Step 3: Start Using the SDK
So, you want to send a message. For demonstration purposes, we’ll use environment variables to authorize the SDK with your personal access token. If you're logged into this site, you can find your token in Getting Started. This token provides access to your account for testing purposes, and shouldn't be used for anything other than testing. If you don't already have a Webex account, click Sign Up at the top of this page to create a new account.
Create a new file in your project directory named index.js
and add the following to it:
var webex = require('webex/env');
webex.rooms.create({
title: 'My First Room!'
})
// Make sure to log errors in case something goes wrong.
.catch(function(reason) {
console.error(reason);
process.exit(1);
});
Now, open the Webex Web Client to you see your code in action. Then, back in your terminal, run the following command:
WEBEX_ACCESS_TOKEN=$YOUR_TOKEN_FROM_THE_PORTAL node index.js
Check out the web client. You should see your new room. Now, let’s send a message to it.
Open up index.js
again and replace its contents with the following code:
var webex = require('webex/env');
webex.rooms.list({
max: 10
})
.then(function(rooms) {
var room = rooms.items.filter(function (room) {
return room.title === 'My First Room!';
})[0];
return webex.messages.create({
text: 'Hello World!',
roomId: room.id
});
})
// Make sure to log errors in case something goes wrong.
.catch(function(reason) {
console.error(reason);
process.exit(1);
});
Run it again with the following:
WEBEX_ACCESS_TOKEN=$YOUR_TOKEN_FROM_THE_PORTAL node index.js
Now check out the web client. Congrats! You’ve sent your first message!
anchorSDK API Reference
anchorIn-depth API reference information for the Node.js SDK API can be found here:
anchorTroubleshooting the Node.js SDK
anchorIf you're having trouble with the Node.js SDK, here's some more information to help troubleshoot the issue.
SDK Requirements
Review the following SDK requirements to make sure you're using the correct minimum versions of Node.js, npm, etc.:
- Node.js LTS 10.x and later
- npm 6.x and later
- Optionally: nvm to manage Node.js versions
- A Webex account and an integration with the necessary scopes
Additional Logging
You can add additional logging to your application to help narrow down any issues with the SDK.
Change the Log Level via an Environment Variable
You can change the log level via the WEBEX_LOG_LEVEL
environment variable. For example, if you start your application server via npm serve
, you'd set the variable before running your application to see increased logging:
WEBEX_LOG_LEVEL=info npm serve
While developing your application, you can set the WEBEX_LOG_LEVEL
environment variable to debug
see even more logging. For example, if you start your application server via npm serve-dev
, you'd set the variable before running your application to see increased logging:
WEBEX_LOG_LEVEL=debug npm serve-dev
Firewall Ports
The Node.js SDK makes use of several network protocols and ports. If you're encountering connection or connectivity issues, make sure there aren't any firewalls blocking or preventing communication with any Webex endpoints. For more information about the network and web security requirements for Webex services, please see Network Requirements for Webex Services.
anchorSupport Policy
anchorPlease visit the Webex API and SDK Support Policy page for details on our support and end of life policy for APIs and SDKs.
Getting Support
If you're stumped, contact the Webex Developer Support team for more help with the SDK.