piersg
February 21, 2023, 11:03am
2
Hmm two things to check:
1. Hubspot no longer allows the use of API keys, you have to use an access token from a private app. If you donβt have that set up, you just need to set up a private app that has access to the hubdb scope. It will then generate a token for you.
2. Double check that the value of HUBDB_API is βhttps://api.hubapi.com/cms/v3/hubdb/tables/ β as the full URL to POST to should be βhttps://api.hubapi.com/cms/v3/hubdb/tables/${HUBDB_TABLE_ID}/draft/publish β
For reference, this works for me:
function updateTable(tableId){
let url = `https://api.hubapi.com/cms/v3/hubdb/tables/${tableId}/draft/publish`;
return fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${token}`,
'accept': 'application/json',
'Content-Type': 'application/json'
}
})
.then(response => ({status: response.stats}));
}
Promise.all([
updateTable([ID1])
updateTable([ID2])
])
.then(data => doMoreThings(data))
.catch(err => console.log(err));