diff --git a/lib/hubspot/hubspot.js b/lib/hubspot/hubspot.js index 8d3bfd5..75e9535 100644 --- a/lib/hubspot/hubspot.js +++ b/lib/hubspot/hubspot.js @@ -62,7 +62,6 @@ hubspotAPI.prototype.execute = function (verbParams, path, availableParams, give var body; var currentParam; var parsedResponse; - var requestOptions; var verb = verbParams && verbParams.verb || verbParams; var headers = { @@ -75,6 +74,12 @@ hubspotAPI.prototype.execute = function (verbParams, path, availableParams, give var finalParams = {}; + var requestOptions = { + method: verb, + headers: headers, + encoding: null + }; + for (var i = 0; i < availableParams.length; i++) { currentParam = availableParams[i]; if (typeof givenParams[currentParam] !== 'undefined') @@ -82,23 +87,19 @@ hubspotAPI.prototype.execute = function (verbParams, path, availableParams, give } /** - * For OAuth: &access_token=TOKEN + * For OAuth 2.0: Set header "Authorization" = "Bearer " + TOKEN * For API Keys: &hapikey=KEY - * @see http://developers.hubspot.com/auth/oauth_overview + * @see http://developers.hubspot.com/docs/methods/auth/oauth-overview */ if (this.api_key) { - authParams.hapikey = this.api_key; + finalParams.hapikey = this.api_key; } if (this.access_token) { - authParams.access_token = this.access_token; + requestOptions.headers["Authorization"] = "Bearer " + this.access_token; } - requestOptions = { - method: verb, - headers: headers, - encoding: null - }; + // some endpoints use array-like parameters that must be stringified. // also must user querystring instead of qs. @@ -119,9 +120,6 @@ hubspotAPI.prototype.execute = function (verbParams, path, availableParams, give requestOptions[verbParams.json ? 'json' : 'form'] = finalParams; uri = uri + "?" + qs.stringify(authParams); - } else { - var allParams = _.merge(authParams, finalParams); - } requestOptions.uri = uri;