Can't get custom objects schemas

I’m trying to get all records of a custom object I created but I can’t seem to get it to work.

const hubspot = require('@hubspot/api-client')
const hubspotClient = new hubspot.Client({
 accessToken: process.env.HUBSPOTTOKEN
})

exports.main = async (event) => {

 hubspotClient.apiRequest({
 method: 'get',
 path: '/crm/v3/schemas',
}).then(response =>{
 console.log(response);
 })
}

This is the custom code in the workflow, I’m first trying to get all schemas to get the custom object ID so that I can later query for all records.

The response logged seems strange to me

2023-09-12T11:13:47.435Z	INFO	Response {
 size: 0,
 timeout: 0,
 [Symbol(Body internals)]: {
 body: Gunzip {
 _writeState: [Uint32Array],
 _readableState: [ReadableState],
 _events: [Object: null prototype],
 _eventsCount: 5,
 _maxListeners: undefined,
 _writableState: [WritableState],
 allowHalfOpen: true,
 bytesWritten: 0,
 _handle: [Zlib],
 _outBuffer: <Buffer 7b 22 72 65 73 75 6c 74 73 22 3a 5b 7b 22 6c 61 62 65 6c 73 22 3a 7b 22 73 69 6e 67 75 6c 61 72 22 3a 22 44 41 55 20 53 6e 61 70 73 68 6f 74 22 2c 22 ... 16334 more bytes>,
 _outOffset: 0,
 _chunkSize: 16384,
 _defaultFlushFlag: 2,
 _finishFlushFlag: 2,
 _defaultFullFlushFlag: 3,
 _info: undefined,
 _maxOutputLength: 4294967296,
 _level: -1,
 _strategy: 0,
 [Symbol(kCapture)]: false,
 [Symbol(kCallback)]: null,
 [Symbol(kError)]: null
 },
 disturbed: false,
 error: null
 },
 [Symbol(Response internals)]: {
 url: 'https://api.hubapi.com/crm/v3/schemas',
 status: 200,
 statusText: 'OK',
 headers: Headers { [Symbol(map)]: [Object: null prototype] },
 counter: 0
 }
}

Memory: 71/128 MB
Runtime: 652.00 ms

Hi @CAntoniades :waving_hand:

You may want to try something like:

const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({accessToken: process.env.HUBSPOTTOKEN});

exports.main = async (event) => {
 const response = await hubspotClient.apiRequest({
 method: 'get',
 path: '/crm/v3/schemas',
 });
 const json = await response.json();
 console.log(json);
}

Based on my testing, this should get you closer to what you want to achieve.

I hope this proves useful. Please let me know if you have any follow-up questions.

Hi @zach_threadint, thanks for the response. Just coming back to this it’s now saying:

INFO	{
 status: 'error',
 message: 'Authentication credentials not found. This API supports OAuth 2.0 authentication and you can find more details at https://developers.hubspot.com/docs/methods/auth/oauth-overview',
 correlationId: '8438c071-09d4-4405-91b9-af9eab0ed1b3',
 category: 'INVALID_AUTHENTICATION'
}

I’ve tried to add the autorization header like so:
hubspotClient.apiRequest({
method: ‘get’,
path: ‘/crm/v3/schemas’,
authorization: ‘Bearer private_app_token’
});

Hi @CAntoniades :waving_hand:

As far as I’m aware, you’ll need to authenticate the hubspotClient when you initiate the instance. So, instead of authenticating each individual request made by your hubspotClient, try authenticating it like this:

const hubspot = require('@hubspot/api-client');
const hubspotClient = new hubspot.Client({accessToken: private_app_token});

I hope this proves useful. Please let me know if you have any follow-up questions.