4 Replies Latest reply on Jun 3, 2020 4:31 AM by Darren Wrigley

    Get custom attributes via API

    Brian T Vance Active Member

      Hi everyone,

       

      I'm looking for a way to get all custom attributes for a resource. Ideally, I'd like to replicate the UI "export" functionality for a resource - but via API instead. I'd like to pass the resource name, specify which objects I want to include, and specify which attributes(and their values) should be returned.

       

      Does anyone have an idea if there is an API(or set of APIs) that could do this?

       

      Also, anyone have any good tips on a JSON to CSV converter? 

       

      Thanks so much!

        • 1. Re: Get custom attributes via API
          Darren Wrigley Guru

          you could use the bulk export from search, using the api. that will get you a csv formatted exactly like you have with the UI.

           

          to do that - you would use the following endpoints:-

           

          1 - create the search export job using 2/catalog/jobs/searchExports    
               passing the search string and the attribute(s) to search for (using the attribute id)

          example: export any objects in the acme_crm resource using the attribute with id com.infa.appmodels.ldm.LDM_4e331e89_8118_4f09_9844_467baa2efcaa

          {

            "attributeIds": [

              "com.infa.appmodels.ldm.LDM_4e331e89_8118_4f09_9844_467baa2efcaa"

            ],

            "q": "+core.resourceName:acme_crm +com.infa.appmodels.ldm.LDM_4e331e89_8118_4f09_9844_467baa2efcaa:*"

          }

          the resultset gives you the jobId for the export job - which you can download using 2/catalog/jobs/resourceExports/{jobid}/result

           

           

          the other way - create a script to execute the search for any/all custom attributes, then process the results. 

          if you are using/familar with python - pandas has some good capabilities to flatten json.  but iterating over the results and writing the exact format you want (to csv, excel etc) is not difficult.

           

           

          • 2. Re: Get custom attributes via API
            Brian T Vance Active Member

            Hi Darren,

             

            Thanks so much for the help. I'm looking at the APIs and can't seem to find the ones you are referencing. Are these available in 10.2.2?  Sorry if I am missing something obvious here.

             

            Thanks!

            • 3. Re: Get custom attributes via API
              Utkarsh Pandey Active Member

              Hi Brian

               

               

              We can use the below API :-

               

               

              /access/2/catalog/models/attributes GET

               

               

              The package ID parameter 'id', we need to provide com.infa.appmodels.ldm

               

               

              All the custom attributes will be registered to this package And the  attributes list will be in the JSON response. This will list all of the custom attributes ever created in the Catalog.

               

               

              Below is the example :-

               

               

              Use the following rest API to get all the custom attribute list:

               

               

              http://<edchost>:<port>/access/1/catalog/models/packages/com.infa.appmodels.ldm?pageSize=100000

               

              http://<host>:<port>/access/2/catalog/data/objects?q=<objects_id>&offset=0&pageSize=100000&related=false

              • 4. Re: Get custom attributes via API
                Darren Wrigley Guru

                Hi Brian,

                search export (for both UI and api) was added starting with v10.4.

                for older versions like 10.2.2hf1 - you can only export custom attribute contents at the resource level - using /1/catalog/data/bulk