Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Released version 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hmschreiner committed May 29, 2017
1 parent ef1bd0d commit 962d96d
Show file tree
Hide file tree
Showing 7 changed files with 192 additions and 34 deletions.
105 changes: 74 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

A wrapper for the HubSpot API based on Node - http://developers.hubspot.com/docs/overview

## Version 1.0
First stable release is now available [here](https://github.com/hmschreiner/node-hubspot-api/releases/tag/v1.0.0).

## Installation

`npm install node-hubspot-api --save`
Expand All @@ -26,12 +29,12 @@ const api = new NodeHubSpotApi('your_api_key')
#### - Get all contacts
Return all contacts that have been created. A paginated list of contacts will be returned with a maximum of 100 contacts per page.

Parameter | Description | Required | Default
--------- | ----------- | :------: | :-----:
**count** | Specify the amount of contacts to return. | No | 20
**vidOffset** | Used to page through the contacts. | No | -
**property** | By default, only a few standard properties will be included in the response data. Include the 'property' parameter to get the specified property in the response. | No | -
**showListMemberships** | Indicate whether current list memberships should be fetched for the contact. | No | false
| Parameter | Description | Required | Default |
| --------- | ----------- | :------: | :-----: |
| **count** | Specify the amount of contacts to return. | No | 20 |
| **vidOffset** | Used to page through the contacts. | No | - |
| **property** | By default, only a few standard properties will be included in the response data. Include the 'property' parameter to get the specified property in the response. | No | - |
| **showListMemberships** | Indicate whether current list memberships should be fetched for the contact. | No | false |

**Usage:**
```javascript
Expand Down Expand Up @@ -140,13 +143,13 @@ https://developers.hubspot.com/docs/methods/contacts/create_or_update
#### - Get all blogs
List all of the blogs for a portal. Supports paging and filtering.

Parameter | Description | Required | Default
--------- | ----------- | :------: | :-----:
**limit** | The number of items to return. | No | 20
**offset** | The offset set to start returning rows from. | No | 0
**created** | exact, range, gt, gte, lt, lte - When the post was first created, in milliseconds since the epoch. | No | -
**deleted_at** | exact, gt, gte - When the post was deleted, in milliseconds since the epoch. Zero if the blog post was never deleted. | No | -
**name** | exact, in - The internal name of the blog | No | -
| Parameter | Description | Required | Default |
| --------- | ----------- | :------: | :-----: |
| **limit** | The number of items to return. | No | 20 |
| **offset** | The offset set to start returning rows from. | No | 0
| **created** | exact, range, gt, gte, lt, lte - When the post was first created, in milliseconds since the epoch. | No | - |
| **deleted_at** | exact, gt, gte - When the post was deleted, in milliseconds since the epoch. Zero if the blog post was never deleted. | No | - |
| **name** | exact, in - The internal name of the blog | No | - |

**Usage:**
```javascript
Expand All @@ -166,21 +169,21 @@ api.blog.getAllBlogs({
#### - List blog posts
Get the posts from your blogs.

Parameter | Description | Required | Default
--------- | ----------- | :------: | :-----:
**limit** | The number of items to return. | No | 20
**offset** | The offset set to start returning rows from. | No | 0
**archived** | Returns the posts that match the boolean lookup (e.g. archived=false returns all posts currently not archived). | No | false
**blog_author_id** | Returns the posts that match a particular blog author ID value. | No | -
**campaign** | Returns the posts that match the campaign guid. | No | -
**content_group_id** | Returns the posts that match the blog guid. The blog guid can be found in the blog dashboard URL (e.g. https://app.hubspot.com/blog/:portal_id/dashboard/:blog_guid). | No | -
**created** | Returns the posts that match a particular created time value. Supports exact, range, gt, gte, lt, lte lookups. | No | -
**deleted_at** | Returns the posts that match a particular deleted time value. Supports exact, gt, gte, lt, lte lookups. | No | -
**name** | Returns the posts that match the name value. Supports exact, contains, icontains, ne lookups. | No | -
**slug** | Returns the posts that match a particular slug value. | No | -
**updated** | Returns the posts that match a particular updated time. Supports exact, range, gt, gte, lt, lte lookups. | No | -
**state** | DRAFT, PUBLISHED, or SCHEDULED. | No | PUBLISHED
**order_by** | Return the posts ordered by a particular field value. Blog posts can currently only be sorted by publish_date. Use a negative value to sort in descending order (e.g. order_by=-publish_date). | No | publish_date
| Parameter | Description | Required | Default |
| --------- | ----------- | :------: | :-----: |
| **limit** | The number of items to return. | No | 20 |
| **offset** | The offset set to start returning rows from. | No | 0 |
| **archived** | Returns the posts that match the boolean lookup (e.g. archived=false returns all posts currently not archived). | No | false |
| **blog_author_id** | Returns the posts that match a particular blog author ID value. | No | - |
| **campaign** | Returns the posts that match the campaign guid. | No | - |
| **content_group_id** | Returns the posts that match the blog guid. The blog guid can be found in the blog dashboard URL (e.g. https://app.hubspot.com/blog/:portal_id/dashboard/:blog_guid). | No | - |
| **created** | Returns the posts that match a particular created time value. Supports exact, range, gt, gte, lt, lte lookups. | No | - |
| **deleted_at** | Returns the posts that match a particular deleted time value. Supports exact, gt, gte, lt, lte lookups. | No | - |
| **name** | Returns the posts that match the name value. Supports exact, contains, icontains, ne lookups. | No | - |
| **slug** | Returns the posts that match a particular slug value. | No | -
| **updated** | Returns the posts that match a particular updated time. Supports exact, range, gt, gte, lt, lte lookups. | No | - |
| **state** | DRAFT, PUBLISHED, or SCHEDULED. | No | PUBLISHED |
| **order_by** | Return the posts ordered by a particular field value. Blog posts can currently only be sorted by publish_date. Use a negative value to sort in descending order (e.g. order_by=-publish_date). | No | publish_date |

**Usage:**
```javascript
Expand Down Expand Up @@ -217,7 +220,47 @@ api.blog.getPostById(3198892953)
**Reference:**
http://developers.hubspot.com/docs/methods/blogv2/get_blog_posts_blog_post_id

## Disclaimer
This tool is under development and don't have a stable version yet.
### Deals

#### - Create a deal
This methods creates a deal on HubSpot. You can create associations between Deals and Contacts and Companies but it's not required.

The **dealstage** property is required when creating a deal. If the **pipeline** property is not specified, the default pipeline is assumed. However, it is recommended to always specify the pipeline, especially on portals with multiple pipelines.

Returns a 200 on success with the data for the newly created deal in the response.

*DO NOT USE IT IN PRODUCTION!*
You must pass an object to the method with these parameters:

| Parameter | Description |
| --------- | ----------- |
| Associated records | `"associations": {}` - A set of IDs for records that the new deal should be associated with. Deals can be associated with a single company (associatedCompanyIds) and any number of contacts (associatedVids). |
| Deal properties | `"properties": []` - A list of property names, and the value you want to set for the property. |

**Usage:**
```javascript
api.deals.createDeal({
associations: {
associatedCompanyIds: [
123456
],
associatedVids: [
1234, 12345, 123456, ...
],
},
properties: {
dealname: 'This is a brand new deal. Awesome!',
hubspot_owner_id: 123456,
amount: '50000',
dealtype: 'newbusiness',
dealstage: 'appointmentscheduled',
},
})
.then(response => console.log(response.data))
.catch(error => console.error(error))
```

**Reference:**
https://developers.hubspot.com/docs/methods/deals/create_deal

## Disclaimer
This tool is under development and don't have all HubSpot API endpoints implemented yet.
47 changes: 47 additions & 0 deletions dist/endpoints/deals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _errorHandler = require('../helpers/errorHandler');

var _errorHandler2 = _interopRequireDefault(_errorHandler);

var _responseHandler = require('../helpers/responseHandler');

var _responseHandler2 = _interopRequireDefault(_responseHandler);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

var Deals = function Deals() {
var api = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;


if (api === null) throw new Error('Request instance must be provided on constructor.');

return {
createDeal: function createDeal(parameters) {
var properties = parameters.properties,
associations = parameters.associations;


var mappedProperties = Object.keys(properties).map(function (property) {
return {
value: properties[property],
name: property
};
});

return api.post('deals/v1/deal', { properties: [].concat(_toConsumableArray(mappedProperties)), associations: associations }).then(function (response) {
return (0, _responseHandler2.default)(response);
}).catch(function (error) {
return (0, _errorHandler2.default)(error);
});
}
};
};

exports.default = Deals;
6 changes: 5 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ var _blog = require('./endpoints/blog');

var _blog2 = _interopRequireDefault(_blog);

var _deals = require('./endpoints/deals');

var _deals2 = _interopRequireDefault(_deals);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var NodeHubSpotApi = function NodeHubSpotApi() {
Expand All @@ -27,7 +31,7 @@ var NodeHubSpotApi = function NodeHubSpotApi() {
blog: (0, _blog2.default)(api),
domains: null,
files: null,
deals: null
deals: (0, _deals2.default)(api)
};
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-hubspot-api",
"version": "0.4.0",
"version": "1.0.0",
"description": "A wrapper for the HubSpot API based on Node.",
"main": "./dist/index.js",
"scripts": {
Expand Down
25 changes: 25 additions & 0 deletions src/endpoints/deals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import errorHandler from '../helpers/errorHandler'
import responseHandler from '../helpers/responseHandler'

const Deals = (api = null) => {

if (api === null) throw new Error('Request instance must be provided on constructor.')

return {
createDeal(parameters) {

let { properties, associations } = parameters

let mappedProperties = Object.keys(properties).map(property => ({
value: properties[property],
name: property,
}))

return api.post('deals/v1/deal', {properties: [ ...mappedProperties ], associations})
.then(response => responseHandler(response))
.catch(error => errorHandler(error))
},
}
}

export default Deals
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Request from './helpers/request'
import Contacts from './endpoints/contacts'
import Blog from './endpoints/blog'
import Deals from './endpoints/deals'

const NodeHubSpotApi = (apiKey = null) => {

Expand All @@ -13,7 +14,7 @@ const NodeHubSpotApi = (apiKey = null) => {
blog: Blog(api),
domains: null,
files: null,
deals: null,
deals: Deals(api),
}
}

Expand Down
38 changes: 38 additions & 0 deletions test/deals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import chai from 'chai'
import api from './setup'

let expect = chai.expect

describe('Deals', () => {

describe('Create a deal', () => {

it('Should return the data for the newly created deal', done => {

let dealInfo = {
associations: {
associatedCompanyIds: [], // Optional - companies association ID's
associatedVids: [], // Optional - contacts association ID's
},
properties: {
dealname: 'This is a brand new deal. Awesome!',
hubspot_owner_id: '70', // demo user ID,
amount: '50000',
dealtype: 'newbusiness',
},
}

api.deals.createDeal(dealInfo)
.then(response => {
expect(response.status).to.equal(200)
expect(response.data).to.be.a('object')
expect(response.data.properties.dealname.value).to.be.equal(dealInfo.properties.dealname)
expect(response.data.properties.hubspot_owner_id.value).to.be.equal(dealInfo.properties.hubspot_owner_id)
expect(response.data.properties.amount.value).to.be.equal(dealInfo.properties.amount)
expect(response.data.properties.dealtype.value).to.be.equal(dealInfo.properties.dealtype)
done()
})
.catch(error => done(error))
})
})
})

0 comments on commit 962d96d

Please sign in to comment.