@evokegroup/salesforce
v2.0.1
Published
Library for limited Salesforce integration
Downloads
7
Keywords
Readme
@evokegroup/salesforce
Library for limited Salesforce integration
Class: Salesforce
Class: Salesforce.Api
constructor(args)
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| authorizer | OAuth2.Authorizer
| | |
| clientId | string
| | |
| clientSecret | string
| | |
| subdomain | string
| | |
| authOrigin | string
| auth.marketingcloudapis.com
| |
| restOrigin | string
| rest.marketingcloudapis.com
| |
| timeout | number
| 30000
| |
| logger | Logger
, | | A Logger
to output logs to |
authenticate() => Promise<OAuth2.AccessToken>
Authenticates. Called automatically.
dataQuery(args)
Queries a data extension. The filter + fields query string character length must be <= 2048 characters when url encoded. See Utility.createDataQueryValueBatches
to break large queries into batches.
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| dataExtension | string
| | The name of the data extension to query |
| filter | Salesforce.Api.FilterGroup
, Salesforce.Api.Filter
| | The query filter |
| fields | Array<string>
| | The fields to return |
| output | Salesforce.Api.OutputFormat
| Salesforce.Api.OutputFormat.Json
| The output format |
| transform | boolean
| true
| Transforms the data returned to match the fields given |
const Salesforce = require('@evokegroup/salesforce');
const sf = new Salesforce.Api({
subdomain: 'abc123',
clientId: 'qwer456',
clientSecret: 'poiu0987'
});
sf.dataQuery({
dataExtension: 'DE_Custom_Contact',
filter: new Salesforce.Api.FilterGroup({
type: Salesforce.Api.FilterGroupType.And,
filters: [
new Salesforce.Api.FilterGroup({
type: Salesforce.Api.FilterGroupType.Or,
filters: [
new Salesforce.Api.Filter({
key: 'Contact Key',
value: 'guid-1'
}),
new Salesforce.Api.Filter({
key: 'Contact Key',
value: 'guid-2'
})
]
}),
new Salesforce.Api.Filter({
key: 'Custom Field Name',
value: 'Evoke'
})
]
}),
fields: ['Contact Key', 'Custom Field Name', 'Another Field']
})
.then((data) => {
console.log(data);
/*
[{
'Contact Key': 'guid-1',
'Custom Field Name': 'Evoke',
'Another Field': 'abc'
}, {
'Contact Key': 'guid-2',
'Custom Field Name': 'Evoke',
'Another Field': 'def'
}]
*/
})
.catch((ex) => {
console.log(ex);
});
dataInsertAsync(args)
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| dataExtension | string
| | The name of the data extension |
| items | Array<object>
| | The data items to insert |
| output | Api.OutputFormat
, Salesforce.Api.OutputFormat
| Salesforce.Api.OutputFormat.Json
| The output format |
dataUpsertAsync(args)
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| dataExtension | string
| | The name of the data extension |
| items | object
| | The data extension data to upsert |
| output | Salesforce.Api.OutputFormat
| Salesforce.Api.OutputFormat.Json
| |
interactionEvent(args)
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| contactKey | string
| | The contact key |
| eventDefinitionKey | string
| | The event definition key |
| data | object
| | The event data |
| output | Salesforce.Api.OutputFormat
| Salesforce.Api.OutputFormat.Json
| |
Class: Salesforce.Api.TokenAuthorizerV2 extends OAuth2.WebTokenAuthorizer
constructor({ subdomain, clientId, clientSecret, logger, authOrigin, timeout })
Class: Salesforce.Api.Filter
constructor(args)
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| key | string
| | This filter key (typically the field name) |
| value | string
| | The value to filter on |
| comparison | string
| Api.FilterComparison.Equals
| The filter value comparison operator |
Properties
| Name | Type | Default | Description |
| ---- | ---- | ------- | ----------- |
| key | string
| | This filter key (typically the field name) |
| value | string
| | The value to filter on |
| comparison | string
| Api.FilterComparison.Equals
| The filter value comparison operator |
Methods
toQuerystring()
Class: Salesforce.Api.FilterEquals extends Salesforce.Api.Filter
constructor(key, value)
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| key | string
| | This filter key (typically the field name) |
| value | string
| | The value to filter on |
Class: Salesforce.Api.FilterGroup
constructor(args)
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| type | string
| Api.FilterGroupType.And | The operator the join filters with |
| filters | Array<object>
| | An array containing Filter
s and/or FilterGroups
|
Class: Salesforce.Api.FilterGroupAnd extends Salesforce.Api.FilterGroup
constructor(filters[, ...filter])
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| filter | Array<Salesforce.Api.Filter>
, Salesforce.Api.Filter
| | An array of Salesforce.Api.Filter
or any number of filter paramters |
Class: Salesforce.Api.FilterGroupOr extends Salesforce.Api.FilterGroup
constructor(filters[, ...filter])
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| filter | Array<Salesforce.Api.Filter>
, Salesforce.Api.Filter
| | An array of Salesforce.Api.Filter
or any number of filter paramters |
Enumeration: Salesforce.Api.FilterComparison
Enumeration: Salesforce.Api.FilterGroupType
Enumeration: Salesforce.Api.OutputFormat
Class: Salesforce.Constants
static DATA_QUERY_CHARACTER_LIMIT
The maximum number of characters allowed (2048) in a data queries filter and fields.
Class: Salesforce.Utility
static batchItems(items, { maxBytes, encoding })
Create item batches that are less than a given maximum byte size
static createDataQueryValueBatches({ filterKey, filterValues, fields, filterGroupType, filterComparisonType }) => Array<Array>
Separates large queries into batches which will be under the data query maximum character limit. Returns an array of arrays of unique filter values
| Parameter | Type | Default | Description |
| --------- | ---- | ------- | ----------- |
| filterKey | string
| | The filter key |
| filterValues | Array<string>
| | The filter values |
| fields | Array<string>
| | The fields the query would return |
| filterGroupType | Salesforce.Api.FilterGroupType.Or
| | The filter group type |
| filterComparisonType | Salesforce.Api.FilterComparison.Equals
| | The filter comparison |
const values = [...]; // A large number of filter values
const batches = Salesforce.Api.createDataQueryValueBatches({ filterKey: 'Email', filterValues: values, fields: ['Email', 'First Name', 'Last Name'] });
/* batches = [
[...],
[...],
[...]
] */