Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

Hubspot import feature#26

Open
Jaspreet-singh-1032 wants to merge 8 commits into
PostHog:mainfrom
Jaspreet-singh-1032:hubspot-import-feature
Open

Hubspot import feature#26
Jaspreet-singh-1032 wants to merge 8 commits into
PostHog:mainfrom
Jaspreet-singh-1032:hubspot-import-feature

Conversation

@Jaspreet-singh-1032

@Jaspreet-singh-1032 Jaspreet-singh-1032 commented Mar 6, 2022

Copy link
Copy Markdown
  • Enrich users on posthog with data from contacts on Hubspot.
  • Enrich user-specified group type with companies information.
  • Enrich user-specified group type with deals information.

Hey guys, let me know if you want me to make any changes.

Comment thread index.js Outdated
Comment thread index.js Outdated
Comment thread plugin.json Outdated
"hint": "Group type that you want to enrich with hubspot companies",
"name": "Company Group Type",
"type": "string",
"default": null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if type is string let's give this a string default

Suggested change
"default": null,
"default": "",

Comment thread plugin.json Outdated
"hint": "Group type that you want to enrich with hubspot deals",
"name": "Deal Group Type",
"type": "string",
"default": null,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Comment thread index.js Outdated
global.hubspotAuth
}&properties=${properties.join(',')}`
}
const authResponse = await fetchWithRetry(requestUrl)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: authResponse implies to me we're just testing auth, not fetching important data

Comment thread index.js Outdated
}
if (res && res['results']) {
for (hubspotDeal of res['results']) {
exists = await storage.get(hubspotDeal['id'], false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
exists = await storage.get(hubspotDeal['id'], false)
const exists = await storage.get(hubspotDeal['id'], false)

Comment thread index.js Outdated
if (res && res['results']) {
for (hubspotDeal of res['results']) {
exists = await storage.get(hubspotDeal['id'], false)
if (!exists) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's flip this if around:

if (exists) {} else {}

much easier to read that way

Comment thread index.js Outdated
}
}
let nextDealBatch
res['paging'] && res['paging']['next']

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's just use an if here

Comment thread index.js
return []
}
let requestUrl = await storage.get(NEXT_COMPANY_BATCH_KEY)
const properties = [

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can live at the top-level instead of inside the function

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just because before doing anything I am checking a condition that whether should I run this function or not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right but there's no need to re-initialize this every time the function is called

Jaspreet-singh-1032 and others added 4 commits April 18, 2022 20:59
Co-authored-by: Yakko Majuri <38760734+yakkomajuri@users.noreply.github.com>
Co-authored-by: Yakko Majuri <38760734+yakkomajuri@users.noreply.github.com>
Comment thread index.js
}

export async function setupPlugin({ config, global }) {
async function setupPlugin({ config, global }) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we removing export? this should be here. all plugin functions should be exported

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I have exported it below at the end along with the other exports.

Comment thread index.test.js
const { resetMeta } = require('@posthog/plugin-scaffold/test/utils')
const { fetchAllCompanies, fetchAllDeals } = require('./index')

test('test skip fetching companies if company groupType not set', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these definitely don't test very much

@yakkomajuri yakkomajuri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcushyett-ph this is shaping up - I wonder if someone should test this e2e? i.e. connect to Hubspot and try this out

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants