callCustomerApi
The vcc.callCustomerApi function can be used to interact with the internal VCC Live API (e.g., retrieving or updating record information).
Description
vcc.callCustomerApi(method, url, data, callback);
Calls a specified VCC Database API with a specified record. The callback will be invoked when the API call has finished.
Parameters
method
The HTTP method to use for the request (e.g., 'GET', 'POST', 'PUT', 'DELETE').
url
The endpoint URL. It can be a relative path for the VCC internal API (e.g., '/v2/projects/{projectid}/records/{numberid}').
data
Payload object for the specified VCC Database API call. (For the three parameters above, refer to the VCC Database API article.) Populate it with ‘null’ if you are using the GET method.
callback
Callback function that runs when the API call has finished. It receives two arguments:
success(Boolean): Indicates whether the API call was successful (true) or failed (false).response(Object): The parsed JSON response object returned by the API.
Return values
This function does not return a value directly (undefined). The result of the API call is handled asynchronously via the provided callback function.
Use cases with explanation
1. Fetching the VCC record data to determine if a call was lost in the queue
You can call the VCC V2 API internally, utilizing a relative path. In this scenario, we check the events of the current record on load. If it matches a specific description, we update a script field.
$().onLoad = function() {
var projectId = vcc.getScriptVariable('project.id');
var recordId = vcc.getScriptVariable('numberid');
// Internal VCC call, requesting the current record's details
vcc.callCustomerApi('GET', '/v2/projects/' + projectId + '/records/' + recordId, null, function(success, response) {
if (success && response && response.response && response.response.events) {
// Filter the events for a specific description
var lostEvents = response.response.events.filter(function(event) {
return event.description === 'Lost call in queue';
});
// If the event occurred, update a script field and refresh the page
if (lostEvents.length > 0) {
vcc.setFieldValue('is_lost_call', 'yes');
vcc.getController('customer_page', 'is_lost_call').refresh();
}
}
});
};
2. Automatically pushing disposition data to another project
Using the beforeSetDisposition hook, you can trigger a POST request to automatically copy over caller details to a fallback project immediately upon selecting a disposition.
$().beforeSetDisposition = function(disposition, comment) {
// Check if the chosen disposition ID matches a specific code (e.g., 15 for 'Successful')
if (disposition.id === 15) {
var payload = {
phone1: vcc.getFieldValue('phone1'),
operator: vcc.getScriptVariable('agent.name'),
source_project: vcc.getScriptVariable('project.name'),
short_id: vcc.getScriptVariable('global.shortid')
};
// Send a POST request to save the record in another project
vcc.callCustomerApi('POST', '/v2/projects/9999/records', payload, function(success, response) {
if (success) {
dump('Successfully transferred record: ' + JSON.stringify(payload));
} else {
dump('Failed to transfer record.');
}
});
}
};
Notes
vcc.callCustomerApiexecutes asynchronously. Any logic that relies on the returned data must be placed inside thecallbackfunction.- Using relative paths (e.g.,
'/v2/projects...') will automatically target the current VCC instance’s internal API. In this case, the authentication happens inherently through the agent’s active session.
Comments
Can’t find what you need? Use the comment section below to connect with others, get answers from our experts, or share your ideas with us.
There are no comments yet.