I am building an app that needs the data of the requested items for the service request placed on the Freshservice Service Catalog. Looks like subdomain.freshservice.com/api/v2/tickets/[id]/requested_items
is the endpoint I am looking for.
However the documentation states requested_items
to be of Type -
Should I imagine this to be an Array? So that I can apply Array.prototype.map()
on it?
Is it a Object?
The response looks something like this:
{
requested_items: [
{
custom_fields: {},
id: 14000753082,
created_at: '2021-12-17T05:17:42Z',
updated_at: '2021-12-17T05:17:42Z',
quantity: 1,
stage: 1,
loaned: false,
cost_per_request: 0,
remarks: null,
delivery_time: null,
is_parent: true,
service_item_id: 31
}
]
}
OK. Now it looks like an Array of Objects. Each item in the array appears like it lists the details of the service request raised by the user. But from the UI it appears like a ticket is created for each service request raised. User can request one service request at a time? If that’s true why is this array of objects?
As a result, I’m now confused to implement logic in my app as follows:
- Should I always access response as
response[0]
and do.requested_items
to access the data I need? - Should I always assume the response is a Array of objects following the schema for every object within and implement
response.map()
?