I'm just starting out trying to make my first API call to HS. I'm a complete NOOB. I think what I'm doing might be getting phased out but I wanted to start here and work my way up. I am using VS Code and have a handful of extensions installed. (REST Client / Thunder ) I have node.JS installed. Outside of Hubspot, I've been able to successfully run a "GET" call to a test website and it returned JSON data.
I'm now looking at some archived instructions per the snippet below. I've created a private app (access to literally all options) and have my token ready.
I've tried pasting the node.JS code (below) into VScode and also tried a GET command on the example http address shown in the snippet (with my token pasted in) but neither is working.
I tried this with my own email address (which is a contact in HS) and I'm getting a message that the Hapikey does not exist.
UPDATE:
I bounced completely over to POSTMAN and ran a GET as shown below:
1.) My private app token is stored as a secret Global variable
Let's start with this endpoint — Get a contact by email address. Looking at your screenshot, it looks like you are trying to include your bearer token in the request URL. This won't work. Private Apps, and OAuth, require you to send the Authorization in the header. Meaning, instead of including it in the URL like the example:
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://api.hubapi.com/contacts/v1/contact/email/bob@bobsburgers.com/profile',
'headers': {
'Authorization': 'Bearer pat-na1-NOPE'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
For your second question, we can also use Postman to help us out. What tricky about this one is getting the request URL set up correctly, so you can search by email address instead of ID.
It seems like the way you're trying to include the bearer token in Postman is different from how I do it. I'll add screenshots of what my set-up looks like below.
Here's an example:
Request:
GET https://api.hubapi.com/crm/v3/objects/contacts/tina%40bobsburgers.com?archived=false&idProperty=email
Thank you very much for the response. I've actually had great luck today in Postman. (after weeks of struggling) I'm going to hold off on VS Code for a while and just get everything working that I want to use in PM. I'm now able to use PM and successfully used Gets for contact info/ all owners / and to get ticket details. See image below. Currently stuck on creating a ticket though so if you have a comment on this "The request body may not be null" that's where I'm at.
In this case "hubspot_owner_ID" 104607097 should be me.
Hey hey, @SMCNULTY! Let's take a look at my request, and maybe you can spot what's different on your end. Additionally, can you grab a screenshot of how your request body is set in Postman, please?
In the body tab, I set mine to “raw” and “JSON”. Like this:
Here's my request URL, JSON body, and the response using the Tickets API and an example request body from the page — CRM API | Tickets.
Mar 20, 202310:59 AM - edited Mar 20, 202311:12 AM
Participant
Trying my first API call from VS Code
SOLVE
Interestingly enough I have nothing (well a '1') in my POST Body. I checked my "working" GET body's and those also all show '1'. The Get's work but the Post does not.
I'm not sure why nothing is showing up in the Body>raw>JSON field.
>>EDIT>> I put the JSON code into the RAW>BODY of my create ticket POST and I was able to create a ticket. That's good. Just not sure why when I put the fields in under parameters tab it didn't do the same thing. This may be more of a Postman forum question than HS so ok to close this out if needed.
Let's start with this endpoint — Get a contact by email address. Looking at your screenshot, it looks like you are trying to include your bearer token in the request URL. This won't work. Private Apps, and OAuth, require you to send the Authorization in the header. Meaning, instead of including it in the URL like the example:
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://api.hubapi.com/contacts/v1/contact/email/bob@bobsburgers.com/profile',
'headers': {
'Authorization': 'Bearer pat-na1-NOPE'
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
For your second question, we can also use Postman to help us out. What tricky about this one is getting the request URL set up correctly, so you can search by email address instead of ID.
It seems like the way you're trying to include the bearer token in Postman is different from how I do it. I'll add screenshots of what my set-up looks like below.
Here's an example:
Request:
GET https://api.hubapi.com/crm/v3/objects/contacts/tina%40bobsburgers.com?archived=false&idProperty=email