'Type' in Freshservice API documentation 🤷(is not datatype)

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 - :man_shrugging:

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:

  1. Should I always access response as response[0] and do .requested_items to access the data I need?
  2. Should I always assume the response is a Array of objects following the schema for every object within and implement response.map() ?

This is a very convoluted API. Plus, our API documentation leaves much to the developer’s imagination. :sigh:

This is definitely not clear from the documentation. The only thing I can think of is the endpoint for creating a service request can take multiple “service items” as child_items. I would assume these are the items returned by the View Requested Items of a Service Request endpoint.

Even that endpoint’s behaviour is weird because looks like it takes in an object, so there will only be a single quantity property for any number of child_items.

That will break. Assuming response is the parsed JSON body, it will be an Object.

So, you should check if Array.isArray(response.requested_items), then do response.requested_items.map(fn),