Using cURL and the Terminal to Test BPCC REST APIs
If you need to test Bright Pattern Contact Center (BPCC) REST APIs, note that you may do so by using cURL and your computer’s terminal. If your company maintains a website, it will use the server-side scripts to perform similar actions. Installing cURL for the Windows OS is a fairly simple process; Mac OS has cURL installed by default.
This tutorial uses the BPCC List Management API to add a record to an existing .CSV list and then return all records from the list. For information regarding uploading calling lists, see Tutorials for Admins, section Lists.
Notes:
Procedure
- Verify that your Bright Pattern Contact Center user has access for the appropriate API.
- Open your terminal.
- If you are on a Mac, make sure you are running bash and not zsh.
- If you are running zsh, here is how to change it to bash.
- If you are running zsh, here is how to change it to bash.
Obtaining API Authentication with Get Access Token
Before making any BPCC REST API requests, you must first be authenticated to do so by the system. Most BPCC APIs use OAuth for authentication, which provides the user with a Bearer access token to include in the header of each subsequent API request. The method used for this is called Get Access Token.
In this method, client credentials are used to authenticate clients. The authenticated user is checked for having appropriate privileges to perform the requested operation. Privileges are assigned to users via roles in the Contact Center Administrator.
- Copy and paste the following code into a basic text editor such as notepad.
- curl --location --request POST 'https://<tenant_URL>/configapi/v2/oauth/token' \
- --header 'Content-Type: application/x-www-form-urlencoded' \
- --data-urlencode 'client_id=<user_name>' \
- --data-urlencode 'client_secret=<API_Secret_Generated_Code>' \
- --data-urlencode 'scope=<yourcompany.brightpattern.com>' \
- --data-urlencode 'grant_type=client_credentials'
- Change the underlined areas.
(Please note that the data being provided is still fake data for this example and must be replaced with the data for your own credentials and website.) - Example: <tenant_URL> becomes “server.website.com.”
- <user_name> becomes “yourwebsiteadminloginname.”
- <API_Secret_Generated_Code> becomes “A1B2C3D4E5F6H7I8J9K0L0M9N8P7Q6R5S4T3U2V1W0”
- <yourcompany.brightpattern.com> becomes “server.website.com.”
- Copy the now-edited code.
- Paste the code into the terminal and press “enter”.
- The terminal will return something that looks like this:
- Copy and paste the access_token string into your basic text-editing software/notepad file to save for the next process.
- In this example, the access_token is: A1B2C3D4E5F6H7I8J9K0L0M9N8P7Q6R5S4T3U2V1W0.
- The token_type is “Bearer.”
- In this example, the access_token is: A1B2C3D4E5F6H7I8J9K0L0M9N8P7Q6R5S4T3U2V1W0.
Add a Record
After obtaining the Bearer access token, we will test the List API’s Add Record method, which adds a single new record to the existing calling list.
- Copy and paste the following code into a basic text editor such as notepad and change the underlined areas.
- curl --location --request POST '<tenant_URL>/configapi/v2/callinglist/add/<CSV_list_name>' \
- --header 'Content-Type: application/json' \
- --header 'Authorization: Bearer <access_token_number>' \
- --data-raw '{
- "ID": "some_number",
- "firstName": "some_first_name",
- "lastName": "some_last_name",
- "Email": "some_email_address",
- "PhoneNumber": "some_phone_number"
- }'
- Copy the now-edited code and paste it into the terminal and press “enter”.
- To check that the list can now receive records, go to the Contact Center Administrator application, section Lists.
- Click the center tab, “Contents” and examine the list.
- If the test information has been posted, you have succeeded.
- If it has not, check your request code and review it for any formatting errors (e.g., curly quotes). Note that any returned HTTP response codes are explained in the List API documentation.
- If the test information has been posted, you have succeeded.
Get All Records
For further List API testing, you will use the Get All Records method to review the contents of an existing calling list. The returned list records may be used to pass into some other system, for example, a custom CRM.
Additionally, the returned list contains JSON objects sorted by index. It is recommended that you memorize the last fromIndex to speed up queries to the systems.
- Copy and paste the following code into a basic text editor such as notepad and change the underlined areas.
- curl --location --request POST 'https://<tenant_URL>/configapi/v2/callinglist/getAll/<CSV_list_name>/<campaign_name>' \
- --header 'Content-Type: application/json' \
- --header 'Authorization: Bearer <access_token_number>' \
- --data-raw '{
- "fromIndex": 0,
- "maxSize": "100"
- }'
- Copy the now-edited code and paste it into the terminal and press “enter”.
- If the request is successful, you will receive back all records from the specified list.