Help Accessing Nested Object Attributes with TypeScript using VS Code

Hi Community,

I’m rather new to working with APIs and am trying to execute a call against the IdentitiesBetaApi, targeting the getIdentity method using Visual Studio Code. The call works as it should, and I am getting back the expected object from the service.

However, the specific attribute I need is nested within the parent object. As an example, I need to access the “attributes” nested object, and pull back specific attributes. Below is a snippet of what is returned from the call when executing it from Postman. You will see the nested “attributes” object in the json.

{
        "alias": "nobody",
        "emailAddress": "[email protected]",
        "isManager": false,
        "lastRefresh": "2025-05-15T17:46:40.821Z",
        "processingState": null,
        "identityStatus": "PENDING",
        "attributes": {
            "endDate": "1/1/1753 0:0:0 AM UTC",
            "jobTitle": "Newbie",
            "shift": "1",
            "cgnativeid": "NA"
            }
}

And below is my VS Code. The “val” object which I am returning at the end is being converted to a csv file in another function, and it lists all the attributes as headers, along with their values. One thing I noticed, was that for the attributes that exist within nested objects, the header would be “attributes.locationCode”, for example, while non nested attributes would just show as “firstname”.

I’ve been trying all sorts of things but no luck yet. Can someone point me to documentation or give me an example of how I can pull only the value for “attributes.locationCode”?

import { Configuration, IdentitiesBetaApi } from "sailpoint-api-client"

export const getIdentities = async() => {
    let apiConfig = new Configuration()
    let api = new IdentitiesBetaApi(apiConfig)

    let parameters = {
       
        id: 'someRandomID'
    }

    const val =  await api.getIdentity(parameters)

    return val

   
}

Thanks a lot!

Hello @kelvrobinson

Welcome to the Community :tada:
Try this :

import { Configuration, IdentitiesBetaApi } from "sailpoint-api-client"

export const getIdentities = async () => {
    let apiConfig = new Configuration()
    let api = new IdentitiesBetaApi(apiConfig)

    let parameters = {
        id: 'someRandomID'
    }

    try {
        const response = await api.getIdentity(parameters)

        // Assuming attributes.locationCode as required nested object
        const locationCode = response?.attributes?.locationCode

        return locationCode
    } catch (error) {
        console.error("Error fetching identity nested attribute:", error)
        return null
    }
}