2.0.1 • Published 2 years ago

@evokegroup/salesforce v2.0.1

Weekly downloads
193
License
ISC
Repository
bitbucket
Last release
2 years ago

@evokegroup/salesforce

Library for limited Salesforce integration

Class: Salesforce

Class: Salesforce.Api

constructor(args)

ParameterTypeDefaultDescription
authorizerOAuth2.Authorizer
clientIdstring
clientSecretstring
subdomainstring
authOriginstringauth.marketingcloudapis.com
restOriginstringrest.marketingcloudapis.com
timeoutnumber30000
loggerLogger,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.

ParameterTypeDefaultDescription
dataExtensionstringThe name of the data extension to query
filterSalesforce.Api.FilterGroup, Salesforce.Api.FilterThe query filter
fieldsArray<string>The fields to return
outputSalesforce.Api.OutputFormatSalesforce.Api.OutputFormat.JsonThe output format
transformbooleantrueTransforms 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)

ParameterTypeDefaultDescription
dataExtensionstringThe name of the data extension
itemsArray<object>The data items to insert
outputApi.OutputFormat, Salesforce.Api.OutputFormatSalesforce.Api.OutputFormat.JsonThe output format

dataUpsertAsync(args)

ParameterTypeDefaultDescription
dataExtensionstringThe name of the data extension
itemsobjectThe data extension data to upsert
outputSalesforce.Api.OutputFormatSalesforce.Api.OutputFormat.Json

interactionEvent(args)

ParameterTypeDefaultDescription
contactKeystringThe contact key
eventDefinitionKeystringThe event definition key
dataobjectThe event data
outputSalesforce.Api.OutputFormatSalesforce.Api.OutputFormat.Json

Class: Salesforce.Api.TokenAuthorizerV2 extends OAuth2.WebTokenAuthorizer

constructor({ subdomain, clientId, clientSecret, logger, authOrigin, timeout })

Class: Salesforce.Api.Filter

constructor(args)

ParameterTypeDefaultDescription
keystringThis filter key (typically the field name)
valuestringThe value to filter on
comparisonstringApi.FilterComparison.EqualsThe filter value comparison operator

Properties

NameTypeDefaultDescription
keystringThis filter key (typically the field name)
valuestringThe value to filter on
comparisonstringApi.FilterComparison.EqualsThe filter value comparison operator

Methods

toQuerystring()

Class: Salesforce.Api.FilterEquals extends Salesforce.Api.Filter

constructor(key, value)

ParameterTypeDefaultDescription
keystringThis filter key (typically the field name)
valuestringThe value to filter on

Class: Salesforce.Api.FilterGroup

constructor(args)

ParameterTypeDefaultDescription
typestringApi.FilterGroupType.AndThe operator the join filters with
filtersArray<object>An array containing Filters and/or FilterGroups

Class: Salesforce.Api.FilterGroupAnd extends Salesforce.Api.FilterGroup

constructor(filters, ...filter)

ParameterTypeDefaultDescription
filterArray<Salesforce.Api.Filter>, Salesforce.Api.FilterAn array of Salesforce.Api.Filter or any number of filter paramters

Class: Salesforce.Api.FilterGroupOr extends Salesforce.Api.FilterGroup

constructor(filters, ...filter)

ParameterTypeDefaultDescription
filterArray<Salesforce.Api.Filter>, Salesforce.Api.FilterAn 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

ParameterTypeDefaultDescription
filterKeystringThe filter key
filterValuesArray<string>The filter values
fieldsArray<string>The fields the query would return
filterGroupTypeSalesforce.Api.FilterGroupType.OrThe filter group type
filterComparisonTypeSalesforce.Api.FilterComparison.EqualsThe 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 = [
  [...],
  [...],
  [...]
] */
2.0.1

2 years ago

2.0.0

2 years ago

1.1.3

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago