Get DEAL information when Stage is changed


#1

Hi,
I’m new to APIs and looking for a method to extract all the information pertaining to that one particular DEAL (including the company and customer name info).
My goal is to be able to pull this information out, which i will be plugging into an engagement letter to send to that customer (that portion is already finished with VBA). I just need to find a a way to get the DEAL info out of the system, and somehow pull it into a spreadsheet and save it on a sever, which is where my vba would pull the information into an word document.

I have no idea if this is possible, or really where to start.

anyone’s tips would be greatly appreciated.


#2

@jason_jost You can set up a webhook to know when a deal stage has changed.

Once you have that then you can hit our recently changed endpoint.

This will give you all the information that you would need.


Using Webhook / Deal Property Changed - Deal Stage
#3

@pmanca

Thanks for the tip. this does give me some direction to start working towards. can you provide any other details. Please forgive me, as my understanding of API and webhooks is eqivalent to a 8th grader in a Calculus class. I understand the use of webhooks and APIs, but i dont have any experience in setting them up and getting them to work together.


#4

@jason_jost I would install postman. It is a tool that can help you test out API calls.

Go through the documentation I posted above for receiving the recent deals. Postman will allow you to test out your calls with out having to worry about writing code at all. Once you are receiving what you want/expect then you can worry about writing in the API calls to a script to automate it.


#5

@pmanca
I have been playing around with POSTMAN. my only issue right now is trying to figure out how to setup the Oauth 2.0 so i can make those requests.

Right now, if i try to use an API without the OAuth, i get an error saying i >reached my daily limit", which im assuming is because i dont have an access token setup. I’ve been searching around for the last hour trying to figure out where i get the data fields for that (auth url, access token url, client id, client secret). this is my one hang up right now


#6

@jason_jost How many calls have you made today? Your call limit(40k/day) would be counted for either HAPI key or token authentication. Here is some example code I wrote up on how to do it in NodeJS using PassPortJS as the middleware

var express = require('express')
var passport = require('passport')
var app = express()
var OAuth2Strategy = require('passport-oauth').OAuth2Strategy;

var port = 3000
console.log("i'm on, running at port: " + port)

// used to serialize the user for the session
passport.serializeUser(function(user, done) {
    done(null, user); 
   // where is this user.id going? Are we supposed to access this anywhere?
});

// used to deserialize the user
passport.deserializeUser(function(id, done) {
    User.findById(id, function(err, user) {
        done(err, user);
    });
});

//Dev information can be accessed here: https://app.hubspot.com/developers-beta/2313987/application/38196
passport.use('hubspot', new OAuth2Strategy({
    authorizationURL: 'https://app.hubspot.com/oauth/authorize',
    tokenURL: 'https://api.hubapi.com/oauth/v1/token',
    clientID: 'xxxxx',
    clientSecret: 'xxxxx',
    callbackURL:   'http://localhost:'+port+'/auth/hubspot/callback'
  },
  function(accessToken, refreshToken, profile, done) {
    //console.log('accessToken',accessToken)
    //console.log('profile', profile)
    var authInfo = {
      accessToken:accessToken,
      refreshToken: refreshToken
    }
    request('https://api.hubapi.com/oauth/v1/access-tokens/' + accessToken, function(error, response, body, authInfo){
      if(!error){
        console.log('authInfo', this.authInfo)
        //console.log(JSON.parse(body))
        json_response = JSON.parse(body)
        //console.log(json_response.user)
        //console.log(json_response.hub_id)
        var accessToken = this.authInfo.accessToken
        var refreshToken = this.authInfo.refreshToken
        User.findOrCreate({ email: json_response.user, hub_id:json_response.hub_id, access_token:accessToken, refresh_token: refreshToken }, function (err, user,created) {
          return done(err, user);
        });
      }
      console.log(error)
    }.bind({authInfo:authInfo}))
     

  }
));



app.get('/auth/hubspot', passport.authenticate('hubspot',{scope:['contacts','content','reports','social','automation','timeline']}));
app.get('/auth/hubspot/callback',  passport.authenticate('hubspot', { failureRedirect: '/login' }),
  function(req, res) {
    // console.log('req.session.passport.user')
    // console.log(req.session.passport.user)
    // console.log('req.session.passport')
    // console.log(req.session.passport)
    // Successful authentication, redirect home.
    res.redirect('/test');
  });

app.listen(port)

Here is our documentation on it.

You would get the secret and clientID yourself. you can follow the docs above to get those.


Using Webhook / Deal Property Changed - Deal Stage
#7

@pmanca

Oh, i havent made any calls today. thats why i knew i wasnt setting it up right when i was tyring to run an API and it was telling me that i was over the limit!

Thanks, I’m going to run through this really quick and see where it takes me.


#8

@pmanca

So here is what i got in. i run this, click on my developer account, and it tells me that there is an error getting integrations permissions.


#9

i do have a token already setup on the other end, but this still doesnt seem to be working.


#10

your call back address should be pointing towards hubspot and not postman. Take a couple good whacks at it and let me know if you make any damage.


#11

In case anyone comes across this post the proper internal name is dealstage not Deal Stage