/
Custom Service Contexts
Custom Service Contexts
You may wish to use Send2CRM service contexts to identify which services should be used for particular purposes.
Adding Contexts
New contexts can be added after service registration.
// Add context to a specific service.
send2crm.services.addContext('customContext', 'myAlias');
// Omit the alias to add to the default service.
send2crm.services.addContext('customContext');
Check if a Service has Context
Test whether a specific service has a context enabled.
let isCustomContext = send2crm.services.hasContext('customContext', 'myAlias');
Find all Services with Context
Use your custom contexts to retrieve a subset of service configurations.
let ctxServices = send2crm.services.getServicesFor('customContext');
// Result:
[
{
alias: 'myAlias',
apiUrl: 'https://example.com',
apiKey: '<key>',
contexts: ['customContext']
}
]
This will return an array of objects with service configuration data, may be empty if no matches.