Skip to main content

Reference

Initialization

The method Copper.init() is used to initialize and setup the SDK. All other SDK methods must be called after this.

Copper.init()

getContext()

The method getContext() returns the context of the current Copper page.

getContext()

Returns

TypeDescription
ObjectCurrent context object

saveContext()

The method save() will save the value to the server and update the Copper UI.

Example

const context = await sdk.getContext();
context.name = "Joe"
context.save()

showModal()

The method showModal() will open the modal in Copper's web page. The url for the modal is set as the url of the embedded app appended with ?location=modal. For example, if the url of the embdded app is https://www.example.com, the modal url is https://www.example.com?location=modal.

Parameter

NameTypeRequiredDescription
DataObjectNoData will be passed to the modal as parameters

Special Parameter

showModal({ width: 300, height: 400, displayHeader: true })

NameTypeRequiredDescription
widthIntegerNoWidth of the modal
heightIntegerNoHeight of the modal
displayHeaderBooleanNoIf display header or not

Example

sdk.showModal({ foo: 'bar'})

closeModal()

The method closeModal() will close the current active modal.

Example

sdk.closeModal()

showFullScreen()

The method showFullScreen() will display the Copper web-app in full-screen mode, with the top and left navs hidden.

Example

sdk.showFullScreen()

closeFullScreen()

The method closeFullScreen() will exit out of full-screen mode and restore the top and left navs.

Example

sdk.closeFullScreen()

setAppUI()

The method setAppUI() will change the UI of the parent Copper's web page.

Parameter

NameTypeRequiredDescription
DataObjectYesData uses json format. Currently six keys in the json are supported:
"count", "height", "width", "disableAddButton", "showActionBar", "isActionBarActive".

Example

sdk.setAppUI({
count: 5, //change the value of counter in app header
width: 500, //change the iframe width (currently supported by modals/action bar)
height: 500, //change the iframe height
disableAddButton: true, //disable the add button in the parent frame above the iframe
showActionBar: true, //show embeddded app iframe for the action bar
isActionBarActive: true, //highlight the action bar icon
allowModals: false, // when true, will set allow-modals in the iframe
})

publishMessage()

The method publishMessage(type, target, data) publishes messages to other locations of the same embedded app.

Parameter

NameTypeRequiredDescription
TypeStringYesType of message. Can be any string
TargetStringYesLocations of the message receiver. Currently supported locations include:
"sidebar", "activity_panel", "action_bar", "profile", "modal".
"*" means all locations except the sender.
DatajsonYesContent of message to be sent

Example

sdk.publishMessage('myMessageType', 'sidebar', {foo: 'bar'})

on()

The method on(type, cb) subscribes to the message type with call back cb.

Parameter

NameTypeRequiredDescription
TypeStringYesMessage type to subscribe
cbFunctionYesCallback function to handle the message

Events

Event NameWhen it is triggered
addButtonClickedWhen app is in the sidebar and + button is clicked
phoneNumberClickedWhen voip configuration is on, and phone is clicked
contextUpdatedWhen the Copper app routing has changed
recordSelectedWhen any item is selected in list view

Example

sdk.on('myMessageType', (msg) => {
console.log(msg)
})

api()

The method api(url, options) will proxy the api call from the Copper api server api.copper.com.

Parameter

NameTypeRequiredDescription
urlStringYesurl of the api. E.g. '/v1/people/1'
OptionsObjectYesOptions for the api call. Two keys are supported 'method' and 'body', where the method's value can be
'GET', 'POST', 'PUT', 'PATCH' and 'DELETE'. Value of 'body' is the data sent to the api end point.

Example

sdk.api('/v1/leads/', {
method: 'POST',
body: JSON.stringify({
name: 'lead name'
})
})

All of the developer api url is supported. The method and data format for each api end point can be found in the Copper's api documentation.

refreshUI()

The method refreshUI(target) will refresh the target's UI section. It is primarily used after the above api(url, options) call to update the UI to reflect the data changed in the server.

Parameter

NameTypeRequiredDescription
TargetObjectYesThe format of the parameter is { name: targetName, data: data }, where targetName can be 'ActivityLog' or 'Related'. 'ActivityLog' data is not required. For 'Related', data format is { type: entityType }.

Example

sdk.refreshUI({ name: 'ActivityLog'})
sdk.refreshUI({ name: 'Related', data: { type: 'lead'}})

logActivity()

The method logActivity(type, details) creates activity logs in the Copper web app.

Parameter

NameTypeRequiredDescription
TypeStringYesActivity log type.
DetailsObjectYesActivity log detail data.

Please check Copper's developer api documentation for activity types and details.

Example

const activityType = 0;  // Activity Type 'note'
const details = 'This is a note';
sdk.logActivity(activityType, details);

createEntity()

The method createEntity(entityType, entityData) creates an entity in the Copper web app.

Parameter

NameTypeRequiredDescription
EntityTypeStringYesEntity type. Supported values: 'lead', 'person', 'company', 'opportunity', 'project', 'task'
entityDataObjectYesEntity data.

Please check Copper's developer api documentation for entity details.

Example

const entityType = 'lead';
const entityData = {
name: 'My Lead',
email: {
email: 'mylead@noemail.com',
category: 'work'
},
phone_numbers: [
{
number: '1234567',
category: 'mobile'
}
]
};
sdk.createEntity(entityType, entityData);

relateEntity()

The method relateEntity(entityType, entityId, target) relates two entities in the Copper web app.

Parameter

NameTypeRequiredDescription
entityTypeStringYesEntity type. Supported values: 'lead', 'person', 'company', 'opportunity', 'project', 'task'
entityIdIntegerYesId of the entity type's record
TargetObjectYesTarget entity to be related to. Format is { id: id, type: entityType }

Please check Copper's developer api documentation for entity details.

Example

const entityType = 'task';
const entityId = 1;
const target = {
id: 10,
type: 'opportunity'
};
sdk.relatedEntity(entityType, entityId, target); //relate opportunity 10 to task 1

This method allows embedded apps to navigate to a specific entity record's page.

Parameter

NameTypeRequiredDescription
entityTypeStringYesEntity type. Supported values: 'lead', 'person', 'company', 'opportunity', 'project', 'task'
entityIdIntegerYesId of the entity type's record

Please check Copper's developer api documentation for entity details.

Example

const entityType = 'task';
const entityId = 1;
sdk.navigateToEntityDetail(entityType, entityId); //navigate to task with id 1

getSelectedRecords()

Get selected records by pageNumber and pageSzie

Parameter

NameTypeRequiredDescription
pageNumberIntegerNopage number
pageSizeIntegerNopage size

Example

await sdk.getSelectedRecords({ pageNumber: 0, pageSize: 100});
// returns
[
{
"id": 165837,
"first_name": "Jason",
"last_name": "Mraz",
"middle_name": null,
...
}
]

getUserInfo()

Get current current user info.

The response will include a list of roles that the User has access to. Copper currently supports three roles:

  • user: The User can use the system normally.
  • admin: The User can perform administrative actions.
  • account_owner: The User is the owner of the Account.

Example

await sdk.getUserInfo();
// returns
{
"account": {
"id": 1,
"name": "Google"
},
"user": {
"email": "larry@google.com"
"id": 1,
"name": "Larry Page",
"roles": ["user", "admin"]
}
}

getConfig()

Get current app and installation config

Example

await sdk.getConfig();
// returns
{
"appConfig": {
"height": 600
},
"config": { // this is installation config
"token": "my_token"
}
}