APIs & Integrations

ESalas7
Member | Diamond Partner
Member | Diamond Partner

I'm getting 401 error with new Hubspot API for publish a hubdb table

SOLVE

With the code bellow i receive this message 

"Request failed with status code 401" that apparently is due to authentication issues, but the access token is right and the scope too for hubdb connections, i don't know why is the error, i'm using it in a serverless function inside my hubspot account.

 

const axios = require('axios');
const accessToken = "My access token recently created";


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

axios.post("https://api.hubapi.com/cms/v3/hubdb/tables/"my table"/draft/publish",
{
headers: {
'Content-Type' : 'application/json',
'Authorization' : `Bearer ${accessToken}`
}
}
)
.then(function (response) {
sendResponse({body: JSON.stringify(response), statusCode: 200})
})
.catch(function (error) {
sendResponse({body: JSON.stringify(error), statusCode: 500})
})
}

0 Upvotes
1 Accepted solution
ESalas7
Solution
Member | Diamond Partner
Member | Diamond Partner

I'm getting 401 error with new Hubspot API for publish a hubdb table

SOLVE

Hi JOConnell2, yes i found the solution changing the code like this.

 

const axios = require('axios');
const accessToken = "My access token recently created";


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

axios.post("https://api.hubapi.com/cms/v3/hubdb/tables/"my table"/draft/publish",
{
headers: {
'Content-Type' : 'application/json',
'Authorization' : `Bearer ${accessToken}`
}
}
)
.then(function (response) {
sendResponse({body: JSON.stringify(response.data), statusCode: 200})
})
.catch(function (error) {
sendResponse({body: error, statusCode: 500})
})
}

 

The only thing i changed was adding de "response.data" into the send response function and magically everything rans perfectly, i hope this works for you too.

View solution in original post

7 Replies 7
VSkyhype
Member

I'm getting 401 error with new Hubspot API for publish a hubdb table

SOLVE

i am facing the same issue,but with tickets api , any update on it ?

 

0 Upvotes
ESalas7
Member | Diamond Partner
Member | Diamond Partner

I'm getting 401 error with new Hubspot API for publish a hubdb table

SOLVE

Hello VSkyhype, i found the solution changing only one thing in the first code i presented.

 

const axios = require('axios');
const accessToken = "My access token recently created";


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

axios.post("https://api.hubapi.com/cms/v3/hubdb/tables/"my table"/draft/publish",
{
headers: {
'Content-Type' : 'application/json',
'Authorization' : `Bearer ${accessToken}`
}
}
)
.then(function (response) {
sendResponse({body: JSON.stringify(response.data), statusCode: 200})
})
.catch(function (error) {
sendResponse({body: error, statusCode: 500})
})
}

 

The only thing i changed was adding de "response.data" into the send response function and magically everything rans perfectly :), i hope this works for you too.

0 Upvotes
VSkyhype
Member

I'm getting 401 error with new Hubspot API for publish a hubdb table

SOLVE

still getting the same error(401) but working perfectly when using postman, I am making axios post request from react app fromtend as:

 
       axios.defaults.headers = {
        "Accept": "application/json",
        "Content-Type": "application/json",
        Authorization: `Bearer ${token}`
      };
      .then((response)=>{
console.log(response.data)

      })
0 Upvotes
ESalas7
Member | Diamond Partner
Member | Diamond Partner

I'm getting 401 error with new Hubspot API for publish a hubdb table

SOLVE

I tried using the code hubspot recommeded from https://developers.hubspot.com/docs/api/cms/hubdb but the path seems to be bad, because it brings me the error "TypeError: Cannot read property 'hubdb' of undefined" when i use "hs logs", so i found this post that apperars to be the same error with other path but i tried with others and i can't found the right one.

JOConnell2
Participant

I'm getting 401 error with new Hubspot API for publish a hubdb table

SOLVE

@ESalas7 Any luck with this? I am stuck in the same position, caught out by the documentation at  https://developers.hubspot.com/docs/api/cms/hubdb which refers to a bad path.

0 Upvotes
ESalas7
Solution
Member | Diamond Partner
Member | Diamond Partner

I'm getting 401 error with new Hubspot API for publish a hubdb table

SOLVE

Hi JOConnell2, yes i found the solution changing the code like this.

 

const axios = require('axios');
const accessToken = "My access token recently created";


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

axios.post("https://api.hubapi.com/cms/v3/hubdb/tables/"my table"/draft/publish",
{
headers: {
'Content-Type' : 'application/json',
'Authorization' : `Bearer ${accessToken}`
}
}
)
.then(function (response) {
sendResponse({body: JSON.stringify(response.data), statusCode: 200})
})
.catch(function (error) {
sendResponse({body: error, statusCode: 500})
})
}

 

The only thing i changed was adding de "response.data" into the send response function and magically everything rans perfectly, i hope this works for you too.

JOConnell2
Participant

I'm getting 401 error with new Hubspot API for publish a hubdb table

SOLVE

@ESalas7 Thanks for that! This worked perfectly. I didn't realise you already replied with this above.  The order of the replies and the indentation was a little confusing. Thanks for your help.

0 Upvotes