Comments (3)
Hi @alex-mironov
It hasn't supported yet.
from hubspot-api-nodejs.
@alex-mironov I was looking into this API endpoint support, as well, but you can use the manual call functions to handle the endpoints for now. Here's what I did in my Node.js app as an example:
/**
* Attempt to opt-in a HubSpot Contact to marketing emails. This should **only** be done with user consent.
*
* @param {email} email The email to attempt to opt in to marketing subscription.
* @returns {Promise} The HubSpot API response object if successful, otherwise logs an error to system.
*/
exports.optInToMarketingEmails = async email => {
// Have to do a manual API call because subscription preferences are not yet wrapped in the SDK
// @see: https://github.com/HubSpot/hubspot-api-nodejs/issues/71
return hubspotClient
.apiRequest({
method: 'POST',
path: '/communication-preferences/v3/subscribe',
body: {
emailAddress: email,
subscriptionId: await this.getMarketingSubscriptionId(),
legalBasis: 'LEGITIMATE_INTEREST_PQL',
legalBasisExplanation:
email +
' expressed interest in further emails when requesting resources at an event.'
}
})
.then(response => {
logging.systemInfo(`${email} gave promotional consent and was opted into HubSpot Marketing emails.`)
return response.body;
})
.catch(e => {
const body = e.response.body;
if (body.message.includes('they have unsubscribed') || body.message.includes('already subscribed')
) {
// Log as informational if contact has previously unsubscribed or is already subscribed.
logging.systemInfo(`${e.response.body.category}: ${e.response.body.message}`, LOG_TYPE);
} else {
logging.systemError(`${e.response.body.category}: ${e.response.body.message}`, LOG_TYPE);
}
});
};
/**
* Gets all existing subscription definitions in the HubSpot instance.
*
* @returns {Promise} All existing subscription definitions in the HubSpot instance.
*/
exports.getSubscriptionDefinitions = async () => {
return hubspotClient
.apiRequest({
method: 'GET',
path: '/communication-preferences/v3/definitions'
})
.then(response => response.body);
};
/**
* Get the subscription statuses for any of the Contact's subscriptions.
*
* @param {email} email The HubSpot Contact's email
* @returns {Promise} A HubSpot API response object with the Contact's communciation preferences.
*/
exports.getUserCommunicationPreferences = async email => {
return hubspotClient
.apiRequest({
method: 'GET',
path: '/communication-preferences/v3/status/email/' + email
})
.then(response => response.body);
};
/**
* Get the subscription ID for the *first* Marketing subscription returned.
*
* @returns {Promise<string>} The first Marketing subscription's ID.
*/
exports.getMarketingSubscriptionId = async () => {
const definitions = await this.getSubscriptionDefinitions();
// This can likely be handled better if multiple subscriptions exist
return definitions.subscriptionDefinitions.find(sub => sub.purpose === 'Marketing').id;
};
The function names could probably be improved, but the usage of communication preferences, subscriptions, and other terminology is a bit intermixed in the documentation.
Also, I'm sure the use of .then().catch()
as well as async/await
is triggering to many, but I just don't like the try/catch
paradigm.. 😄
Hope this helps someone.
from hubspot-api-nodejs.
HI @alex-mironov
The API was add in version 4.1.0
hubspotClient.communicationPreferences
from hubspot-api-nodejs.
Related Issues (20)
- Does this module abstract away batching and pagination?
- Missing Notes endpoint HOT 3
- Question | How to get all notes for a specific deal with the info (property) which deal is pinned HOT 8
- Support for Account Informatio API
- What are the best limiter settings for TEN_SECONDLY_ROLLING HOT 3
- Submit Form data? HOT 6
- Several Import errors : Error: ENOENT: no such file or directory, open '/node_modules/@hubspot/api-client/src/discovery/settings/users/UsersDiscovery.ts' HOT 5
- Can `associations` in creation request be optional? HOT 1
- `crm.objects.basicApi.getById` always throws exception on 404 HOT 10
- Functions API is missing the POST_ACTION_EXECUTION on type definition HOT 2
- Automation functions API createOrReplaceByFunctionType doesn't works HOT 2
- BehavioralEventHttpCompletionRequest Properties Types Are String-Only
- Unable to be authorized while using sdk with accessToken HOT 2
- [Question] - Get Deals By Company HOT 1
- 054999I can't reproduce it.
- Question: how to get all chat conversations of contact (e.g. links to the WhatsApp chat in Hubspot) HOT 2
- idProperty missing in SimplePublicObjectBatchInput.js model HOT 1
- Broken typings for typescript HOT 9
- Undocumented breaking change for the searchApi parameter 'after' HOT 3
- Incomplete typing in crm.imports.coreApi.create prototype (HttpFile)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hubspot-api-nodejs.