Skip to main content

How to set up API integration with BHN

Updated over 2 months ago

This guide outlines how to configure BHN reward point allocation for ARG using the Rival platform. It includes steps for setting up credentials, webhooks, secret keys, whitelisted domains, and scripting to allocate points to participants.

Step 1: Generate BHN secret keys

  1. Log into BHN

  2. From the top navigation bar, go to Settings β†’ API

  3. Click Edit under API access keys

  4. Click Generate new client

  5. Enter a Client Name and click NEXT

  6. BHN will generate a:

    • Client ID

    • Client Secret

πŸ‘‰ Save both values, as they will be added to Rival as secrets.

Step 2: Generate auth secret

  1. bhn_auth secret is base64 encoded string generated using client id and client secret

  2. Paste {{client_id}}:{{client_secret}}

Step 3: Save Secret keys in Rival

Where to Navigate

  1. Go to the Settings tab from the top header (this space is only accessible to Research Domain Admins).

  2. In the left-hand navigation, go to Platforms.

  3. Click on the Secret Key Pairs tab.

  4. Click the βž• Action button to add new secret key pairs.


Secrets to Add

Secret Label

Description

bhn_client_id

BHN client ID

bhn_client_secret

BHN client secret

bhn_auth

Base64 encode string generated in step 2

Step 4: Add whitelisted domain in Rival

Where to Navigate

  1. Go to the Settings tab from the top header (Research Domain Admin access only).

  2. In the left-hand navigation, go to Platforms.

  3. Click on the Whitelisted Domains tab.

  4. Click the βž• Action button to add a new whitelisted domain.

URLs to Whitelist

Step 5: Use Rival chat script to allocate points

sample script to allocate points

-- Assign points to be allocated
local ptsAdd = 50

-- End if RewardPoints is not at least 1
if ptsAdd < 1 then
return 0
end

-- Generate Authorization Token
local authEndpoint = 'https://oauth.rybbon.net/oauth2/token'

local authPayload = {}
local authOptions = {}

authOptions['Authorization'] = 'Basic {{{secrets.bhn_auth}}}'
authOptions['Content-Type'] = 'application/x-www-form-urlencoded'

authPayload['grant_type'] = 'client_credentials'
authPayload['client_id'] = '{{{secrets.bhn_client_id}}}'

local authResult = postHttp(authEndpoint, authPayload, authOptions)
local authStatus = authResult.statusCode

-- End if Authentication call is not successful
if authStatus ~= 200 then
log('BHN Authentication failed.')
return -1
end

local authToken = authResult.data.access_token

-- Retrieve Participant Data + Chat Data (hard codes country to USA)
local respondent = getParticipant()
local respondentEmail = getProfileAttribute("EmailAddress").Value
local respondentName = getProfileAttribute("NAME").Value
local respondentCountry = "USA"
local respondentId = respondent.participantId
local chatName = getChatProperty('name')

-- End if Email or Name does not exist
if respondentEmail == null or respondentName == null then
log('No respondent email or name - points assignment will be skipped.')
return 0
end

-- Add points
local ptsEndpoint = 'https://api.rybbon.net/v2/points'

local ptsPayload = {}
local ptsOptions = {}

ptsOptions['Authorization'] = 'Bearer '..authToken

ptsPayload['email'] = respondentEmail
ptsPayload['points'] = ptsAdd
ptsPayload['firstName'] = respondentName
ptsPayload['country'] = respondentCountry
ptsPayload['referenceId'] = respondentId
ptsPayload['comment'] = 'Points rewarded from '..chatName

local ptsResult = postHttp(ptsEndpoint, ptsPayload, ptsOptions)
local ptsStatus = ptsResult.statusCode

-- End if Points BHN call is not successful
if authStatus ~= 200 then
log('BHN Points Reward failed.')
return 0
end

local ptsAdded = convertToNumber(ptsAdd)
return ptsAdded


​

Did this answer your question?