APIs & Integrations

AJouve
Member

Read a batch of tickets

Hello, I am trying to read a batch of ticket using nodes but I do not really understand how the api works

 

for example, I want to get tickets with id 1, 2 and 3

 

const ticketApiResponse = await hubspotClient.crm.tickets.batchApi.read(false, {properties: ["id"], inputs: [{id: 1, id: 2, id: 3}]});
 
But I always have an empty result
 
BatchResponseSimplePublicObject {
status: 'COMPLETE',
results: [],
requestedAt: undefined,
startedAt: 2021-08-30T19:53:51.531Z,
completedAt: 2021-08-30T19:53:51.531Z,
links: undefined
}
 
I do not understand how to write my batchReadInputSimplePublicObjectId

Thanks
5 Replies 5
AJouve
Member

Read a batch of tickets

Hello,

 

This is the actual code 

const contact = {id: 101}

const contactTicketApiResponse = await hubspotClient.crm.contacts.associationsApi.getAll(contact.id, 'tickets');

const tickets = contactTicketApiResponse.body.results.map(result => result.id);

console.log(tickets);

const batchReadInputSimplePublicObjectId = { properties: ["content"], inputs: [tickets.map(ticket => ({ id: ticket }))] };

console.log(JSON.stringify(batchReadInputSimplePublicObjectId));

const ticketApiResponse = await hubspotClient.crm.tickets.batchApi.read(false, batchReadInputSimplePublicObjectId);

console.log(ticketApiResponse.body);

 

The log of tickets returns [ '453824760', '453895381', '454049008' ]

The logs of batchReadInputSimplePublicObjectId returns 

 

{"properties": ["content"], "inputs":[[{"id": "453824760", "id": "453895381", "id": "454049008"}]]}

 

We also tried with only one array

 

{"properties": ["content"], "inputs":[{"id": "453824760", "id": "453895381", "id": "454049008"}]}

 

The result is always the same 

BatchResponseSimplePublicObject {
status: 'COMPLETE',
results: [],
requestedAt: undefined,
startedAt: 2021-09-02T12:41:11.270Z,
completedAt: 2021-09-02T12:41:11.270Z,
links: undefined
}

 

We always have an empty result

himanshurauthan
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Read a batch of tickets

Hello @AJouve,

 

Can you please share the exact code that you are using (hiding the hapikey)?

 

As this snippet shared above working fine for me.

 

You can also try the endpoint tab here - https://developers.hubspot.com/docs/api/crm/tickets and try with your ticket ids.

 

Regards,

Digital Marketing & Inbound Expert In Growth Hacking Technology
0 Upvotes
himanshurauthan
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Read a batch of tickets

Hi @AJouve,

 

Below is the working code, replace those your_id_here with your real ids and replace the your_api_key and this will work -

 

const hubspot = require('@hubspot/api-client');



const hubspotClient = new hubspot.Client({"apiKey":"your_api_key"});



const batchReadInputSimplePublicObjectId = { properties: ["content"], inputs: [[{"id":"your_ticket_id"},{"id":"your_ticket_id"},{"id":"your_ticket_id"}]] };

const archived = false;



try {

  const apiResponse = await hubspotClient.crm.tickets.batchApi.read(archived, batchReadInputSimplePublicObjectId);

  console.log(JSON.stringify(apiResponse.body, null, 2));

} catch (e) {

  e.message === 'HTTP request failed'

    ? console.error(JSON.stringify(e.response, null, 2))

    : console.error(e)

}

 

Regards,

 

Digital Marketing & Inbound Expert In Growth Hacking Technology
himanshurauthan
Thought Leader | Elite Partner
Thought Leader | Elite Partner

Read a batch of tickets

Hello @AJouve,

 

You can try this code as shared in the endpoints tab of batch read here <https://developers.hubspot.com/docs/api/crm/tickets>

 

const hubspot = require('@hubspot/api-client');

 

const hubspotClient = new hubspot.Client({"apiKey":"YOUR_HUBSPOT_API_KEY"});

 

const batchReadInputSimplePublicObjectId = { properties: ["string"], idProperty: "string", inputs: [{"id":"string"}] };

const archived = false;

 

try {

  const apiResponse = await hubspotClient.crm.tickets.batchApi.read(archived, batchReadInputSimplePublicObjectId);

  console.log(JSON.stringify(apiResponse.body, null, 2));

} catch (e) {

  e.message === 'HTTP request failed'

    ? console.error(JSON.stringify(e.response, null, 2))

    : console.error(e)

}

 

Hope this helps!

 

Regards,

 

Digital Marketing & Inbound Expert In Growth Hacking Technology
AJouve
Member

Read a batch of tickets

Thanks but I need to replace "string" with real values
I do not know where to put my array of tickets id