webdew-logo-new_v2-1
   
webdew-logo-new_v2-1
Close
  • Services
  • Work
  • Resources
    • Knowledge
    • Ebooks
    • Tools
      • Website Audit
      • Website Grader
      • HubSpot ROI
  • Blog
  • About
Let's talk

  • fb-icon-01
  • tw-icon-01
  • insta-icon-01 (1)
  • linkedin-icon-01
  • youtube-icon-01
website-green-icon
Websites
  • Website Designing
  • Website Development
  • Website Migration
  • HubSpot Website
  • WordPress Website
  • Growth-Driven Design
video-blue-icon
Videos
  • 3D Videos
  • 2D Animation
  • Whiteboard Animation
  • Video Ads
  • Explainer Videos
  • Testimonial Videos
  • Onboarding Videos
  • Tutorial Videos
  • Social Media Videos
  • Product Demo Videos
marketing-yellow-icon
Marketing
  • Inbound Marketing
  • Inbound Consulting
  • Marketing Automation
  • Search Engine Optimization
  • Brand Domains
hubspot-red-icon
HubSpot
  • HubSpot Apps
  • HubSpot Themes
  • HubSpot Migration
  • HubSpot Onboarding
  • HubSpot Management
  • HubSpot Development
  • HubSpot Audit
  • Free HubSpot Demo
  • HubSpot Diamond Partner
webdew-logo-new_v2-1
  • Services
  • Work
  • Resources
    • Knowledge
    • Ebooks
    • Tools
      • Website Audit
      • Website Grader
      • HubSpot ROI
  • Blog
  • About
Let's talk

How to create deals in HubSpot using serverless functions?

How to create deals in HubSpot using serverless functions?-vbh
Tag: HubSpot
Author: Guriqbal Singh
Guriqbal Singh
Quick Links

Subscribe to Our Blog

Never Miss Any Update From Us !

If you have read my previous blog, then you might be familiar with the term serverless functions and its usage in HubSpot.

Well! Serverless functions provide a way to create server-side code that further helps you in interacting with HubSpot and other third-party services via APIs. I mostly prefer to work with serverless functions as it allows me to work without worrying about the overhead associated with server management. 

HubSpot Tutorials by webdew

As we know that HubSpot provides a lot of different features with serverless functions, but today we will mainly focus on the most common and highly essential feature, i.e., deals.

Deals are the way to know how much business has been done by the company and what needs to be focused on. The more successful deals are made with the customers, the more growth you will see in your company. 

Deals can be created between companies and are assigned to the contacts. Every deal has its amount, and some will include products and line items that are aligned within the deal.

Why Serverless functions in HubSpot-03As a developer, I will not simply teach you how to generate the deals in HubSpot CMS, but we will discuss how we can create them with API's. Along with this, we will discuss the code of API inside the node.

Top 10 HubSpot management service providers

Are you ready to jump into the process of creating deals in HubSpot using serverless functions.? Let's get started…

Steps to create deals with serverless functions in HubSpot

Step-1 Firstly, for creating deals in serverless functions, you need to install a certain package for which you need to update our package.json file with all the other packages. 

update-packages

{

  "name": "serverless",

  "version": "1.0.0",

  "description": "",

  "main": "index.js",

  "scripts": {

    "test": "echo \"Error: no test specified\" && exit 1"

  },

  "author": "",

  "license": "ISC",

  "dependencies": {

    "axios": "*",

    "express": "*",

    "follow-redirects": "*",

    "http": "*",

    "mailgun-js": "*",

    "paypal-rest-sdk": "^1.8.1",

    "request": "*",

    "stripe": "*",

    "localStorage" : "*",

    "util" : "*"

  }

}

If you don't know how to install npm packages in serverless functions, then you can always read my previous blog to get more information. 

Step-2 Once all these packages are installed, we need to create one endpoint inside our serverless.json file. After this, you need to create the js file in which our deal code will reside.

Now, here you might be thinking about which type or post type your endpoint should be. If so, then I would like to say that it totally depends on one's own choice. 

add-endpoints

Step-3 Once you are done with both the above steps, then you need to focus on the code that we are going to use. 

focus-on-code

// Require axios to make API requests in the function

// Redirect the user

const util = require('util');

const request = util.promisify(require('request'));

const axios = require("axios");

exports.main = (body, sendResponse) => {

    var cou_list = 'abc';

    const HAPI_KEY = 'hub-api-key';

    const vid = 1301;

    var dealname = 'abcdef';

    var time = Date.now(); 

                //var request = require("request");

                var options = { method: 'POST',

                  url: 'https://api.hubapi.com/deals/v1/deal',

                  qs: { hapikey: HAPI_KEY },

                  headers: 

                   { 'Content-Type': 'application/json' },

                  body: 

                   { associations: { associatedCompanyIds: [ ], associatedVids: [ vid ] },

                     properties: 

                      [ { value: dealname, name: 'dealname' },

                        { value: 'checkout_abandoned', name: 'dealstage' },

                        { value: 'default', name: 'pipeline' },

                        { value: time, name: 'closedate' },

                        { value: 425, name: 'amount' },

                        { value: 'newbusiness', name: 'dealtype' } ] },

                    json: true };

  request(options, function (error, response, body) {

                  if (error) throw new Error(error);        

                  sendResponse({body: 'body', statusCode: 200});

                });

sendResponse({body: 'exit', statusCode: 200});

};

Create custom objects in HubSpot using API with this easy guide

Step-4 Now, it's time to add the hub API key of your account. But make sure it is added to the same account where you want to create the deal. 

Don't know how to get the HubSpot API key? 

Well! For this, you need to navigate to settings> integrations> API key. 

Now, here, you can copy your API key and proceed further. For more insight, you can refer to the below-added screenshot. 

hubspot-api-key-1

Step-5 Now, you can assign the deal to a contact/ company or both. For assigning the deal to a contact, you need to add the Vid of that contact in the associated vid parameter, whereas to assign the deal to the company, you need to add the company id inside the associated company ids array.

To know the Vid of the contact, you just need to open the contact and can see its URL. 

vid-of-contact

Step-6 Once you are done with the addition of associations, you need to pass certain parameters, which will include:

  • Deal name (could be any of your product name)
  • Deal stage(deal pipeline name). 

You can follow the below screenshots to get this name. 
click-on-deal
create-deal

  • Pipeline(where you want to send your deal(here we are using the default)

select-pipeline

  • Amount of deal
  • Close data
  • Deal type

Step-7 Once you are done with all the settings, you need to deploy this function, for which you can use the following command. 

“hs functions deploy serverless/serverless.functions”

Step-8 After deploying the function, you can either run the server locally or can do it in your HubSpot. 

deploy-function

Step-9 Now, go to the contact whose Vid you have used and check the deal that is created by you. 

check-created-deal

All done! Congratulations! You have successfully created deals inside serverless functions in HubSpot. Furthermore, if you want to get more information about deal API, then you can refer to this document- https://legacydocs.hubspot.com/docs/methods/deals/create_deal.

The Final Say 

Creating a deal and tracking it in HubSpot using serverless functions is one of the best ways to associate the companies and contacts, which further helps in generating leads. Indeed, creating deals is not a cakewalk, but the above-mentioned steps will surely help you in making the best thing possible. 

So, what are you waiting for? Get ready to create a deal in HubSpot without investing much time and effort. Still want to take the help of experts in making the best use of HubSpot CMS, feel free to contact us.

Top 10 Tips to Hire HubSpot Expert for Business Growth

Related Blogs

How to use serverless functions in HubSpot: A step-by-step guide-vbh
HubSpot

How to use serverless functions in HubSpot: A step-by-step guide

How to install npm packages in serverless functions in HubSpot?-vbh
HubSpot

How to install npm packages in HubSpot serverless functions?

What is the REST API in laravel: Everything you need to know-vbh
Websites

What is the REST API in laravel: Everything you need to know

review-star

Based on 1000+ Reviews on

footer-dot-logo-img
  • Hubspot_Logo-icon
  • clutch_Logo-icon
  • upwork_Logo-icon
  • designrush_Logo-icon
  • goodfirms_Logo-icon
  • g2_Logo-icon
WE ARE GLOBAL
  • US-flag
  • CA-flag
  • IN-flag
  • GB-flag

Copyright © 2019 - 2021 Webdew, Inc. All Rights Reserved

Copyright © 2019 - 2021 Webdew Labs Inc. All Rights Reserved

Copyright © 2016 - 2021 Webdew Private Limited. All Rights Reserved

Copyright © 2019 - 2021 Webdew, Inc. All Rights Reserved

WE ARE SOCIAL
  • fb-icon-01
  • tw-icon-01
  • insta-icon-01 (1)
  • linkedin-icon-01
  • youtube-icon-01
Terms of Services
Privacy Policy