APIs & Integrations

Carol_Saldanha
Member

I'm trying to create a deal with the deals API, for some reason a deal is not getting created

SOLVE

I'm integrating the code via Zapier. I am unable to create a deal.
The code for the same is:

var email = inputData.email;
var postcode = inputData.postcode;
var solar = inputData.solar;
var isbusiness = inputData.isbusiness;
var dealname = inputData.dealname;
var pipeline = 'default';
var dealstage = '8db57d1b-7daa-451d-b242-89450ea3e1b3';

var clienttype;
var state;

if(postcode.substring(0,1) == '3' && isbusiness =='N' ){
state = 'VIC';
clienttype = 'Residential';
}
if(postcode.substring(0,1) == '3' && isbusiness =='Y' ){
state = 'VIC';
clienttype = 'Business';
}

else if (postcode.substring(0,1) == '4' && isbusiness =='N'){
state = 'SA';
clienttype = 'Residential';
}
else if (postcode.substring(0,1) == '4' && isbusiness =='Y'){
state = 'SA';
clienttype = 'Business';
}

else if (postcode.substring(0,1) == '5' && isbusiness =='N'){
state = 'QLD';
console.log("This one");
clienttype = 'Residential';
}
else if (postcode.substring(0,1) == '5' && isbusiness =='Y'){
state = 'QLD';
clienttype = 'Business';
}
else if((postcode >= 2601 && postcode <= 2904) && isbusiness == 'N'){
state = 'ACT';
clienttype = 'Residential';
}
else if((postcode >= 2601 && postcode <= 2904) && isbusiness == 'Y'){
state = 'ACT';
clienttype = 'Business';
}
else if((postcode >= 2575 && postcode <= 2773) && isbusiness == 'N'){
state = 'NSW';
clienttype = 'Residential';
}
else if((postcode >= 2575 && postcode <= 2773) && isbusiness == 'Y'){
state = 'NSW';
clienttype = 'Business';
}
else{
console.log("No condition matched.");
}

var url = "https://api.hubapi.com/deals/v1/deal?hapikey=demo";

var data = {
"properties": [
{
"property": "email_address",
"value": email
},
{
"property": "dealname",
"value": dealname
},
{
"property": "pipeline",
"value": pipeline
},
{
"property": "dealstage",
"value": dealstage
},
{
"property": "postcode",
"value": postcode
},
{
"property": "state",
"value": state
},
{
"property": "solar",
"value": solar
}
]

};

fetch(url, {
method: 'POST',
body: JSON.stringify(data)
}).then(function(response) {

  return response.text();

}).then(function(responsebody) {
var output = {updated: true};
console.log(JSON.stringify(responsebody));
callback(null, output);
}).catch(error => console.error('Error:', error));

0 Upvotes
1 Accepted solution
Carol_Saldanha
Solution
Member

I'm trying to create a deal with the deals API, for some reason a deal is not getting created

SOLVE

Hi, I got this working using curl , but while I integrate it with Zapier, it doesn't work.

View solution in original post

0 Upvotes
6 Replies 6
jackcoldrick
HubSpot Employee
HubSpot Employee

I'm trying to create a deal with the deals API, for some reason a deal is not getting created

SOLVE

Hey Carol, thats good news. Glad you got it working! :slight_smile:

Jack Coldrick
Solutions Engineer @ HubSpot
Add me on LinkedIn
0 Upvotes
jackcoldrick
HubSpot Employee
HubSpot Employee

I'm trying to create a deal with the deals API, for some reason a deal is not getting created

SOLVE

Hi Carol,

Happy to help here. Can you let me know what response (if any) you are getting back when you attempt to hit that endpoint? One thing I've noticed is that the API key specified is "demo" which would not create a deal in the portal you are working from. You should use the API key tied to the specific portal.

If you're getting a 200 response then likely all you'll need to do is replace "demo" with your own hapi key. If you're getting a 4xx error then can you pass on the specifics and we can try and figure out the root cause.
Information on finding your portal HAPI key can be found here:

Jack

Jack Coldrick
Solutions Engineer @ HubSpot
Add me on LinkedIn
0 Upvotes
Carol_Saldanha
Member

I'm trying to create a deal with the deals API, for some reason a deal is not getting created

SOLVE

Hi Jack,

I have added my API key. I didn't add it here, coz of security reasons. Surprisingly, there is no error code and when I do a console log, it outputs nothing(empty). Could you have this resolved today please?

Regards,
Carol

0 Upvotes
Carol_Saldanha
Member

I'm trying to create a deal with the deals API, for some reason a deal is not getting created

SOLVE

Hubspot sets up internal property values for deal dealstage and pipeline. Is it because of that? The internal property for dealstage is 8db57d1b-7daa-451d-b242-89450ea3e1b3. The label value is Sign up started. I used both, it still does not work. Could you test with pushing the same deal values?

0 Upvotes
Carol_Saldanha
Solution
Member

I'm trying to create a deal with the deals API, for some reason a deal is not getting created

SOLVE

Hi, I got this working using curl , but while I integrate it with Zapier, it doesn't work.

0 Upvotes
Carol_Saldanha
Member

I'm trying to create a deal with the deals API, for some reason a deal is not getting created

SOLVE

I fixed it. Thanks anyways. :slight_smile:

0 Upvotes