From Bright Pattern Documentation
Jump to: navigation, search
• 5.19 • 5.8


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:

  • The terminal reads curly quotes and straight quotes (typographically known as “smart quotes” and “dumb quotes”) as two entirely different items. Some word processing programs automatically convert all quotes into curly quotes. When copying and pasting code into the terminal you must verify that the quotes used are straight and not curly quotes.
  • Making requests in Mac terminals and Windows terminals will require different syntaxes. Here is an example article that addresses this topic.

  • Procedure

    1. Verify that your Bright Pattern Contact Center user has access for the appropriate API.
    2. Open your terminal.
      1. If you are on a Mac, this is how you find your terminal.
      2. If you are running Windows, this is how to set up your terminal.
    3. If you are on a Mac, make sure you are running bash and not zsh.
      1. 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.

    1. 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'
    1. 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.)
    2. Example: <tenant_URL> becomes “server.website.com.”
    <user_name> becomes “yourwebsiteadminloginname.”
    <API_Secret_Generated_Code> becomes “A1B2C3D4E5F6H7I8J9K0L0M9N8P7Q6R5S4T3U2V1W0”
    <yourcompany.brightpattern.com> becomes “server.website.com.”
    1. Copy the now-edited code.
    2. Paste the code into the terminal and press “enter”.
    3. The terminal will return something that looks like this:
    4. Copy and paste the access_token string into your basic text-editing software/notepad file to save for the next process.
      1. In this example, the access_token is: A1B2C3D4E5F6H7I8J9K0L0M9N8P7Q6R5S4T3U2V1W0.
      2. The token_type is “Bearer.”


    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.

    1. 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"
    }'


    Screenshot of terminal with code.


    1. Copy the now-edited code and paste it into the terminal and press “enter”.
    2. To check that the list can now receive records, go to the Contact Center Administrator application, section Lists.
    3. Click the center tab, “Contents” and examine the list.
      1. If the test information has been posted, you have succeeded.
      2. 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 you fed in appears in the list, you are successful. Alt: Screenshot of Bright Pattern's List Contents page with areas highlighted


    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.

    1. 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"
    }'
    1. Copy the now-edited code and paste it into the terminal and press “enter”.
    2. If the request is successful, you will receive back all records from the specified list.
    < Previous | Next >