Can I fetch developer app name based on custom attribute?

nsaini
New Member

Hi

We have dynamic client registration URL to create developer app. We are also adding identifier to the apps created in this way. I want to fetch all developer apps having custom attribute value as same. How can I do this?

0 2 338
2 REPLIES 2

nsaini
New Member

Hey!

Thanks for tagging me.

I don't know what you mean by "dynamic client registration URL", but...

I can answer your question - how can I fetch all developer apps having a customer attribute with a specific value?

Here's the thing - the Apigee Edge management database, the thing that stores all the products, developers, apps, credentials, KVM contents, and so on. . . . . is an actual database. And incidentally, it does have somewhat of a graph topology - Developers own" apps, and apps have credentials, which authorize products. . . .

However, this database exposes limited query capability from the management API. There is no SQL support for querying, nor is there a GraphQL mechanism for querying the db, nor anything similar. The querying is pretty rudimentary.

For example, to get the list of API Products, you can do this:

curl -i -H 'Authorization: whatever' \
 -X GET \
 'https://api.enterprise.apigee.com/v1/o/MYORG/apiproducts'

There is a way to get all the apps for a particular product, like this:

curl -i -H 'Authorization: whatever' \
 -X GET \
 'https://api.enterprise.apigee.com/v1/o/MYORG/apiproducts/MYPRODUCT?entity=apps&query=list'

But there is no generalize query capability. There's no way to pass a SQL query, or a SQL-like query, to retrieve the data you want.

Because the server-side query support is rudimentary, the way you can find the things you want is to implement the query, or the filter, on the client side. In your own app.

What I would do is use a scripting language to find the developer apps you seek. It's pretty easy to do in nodejs or powershell, because there are "wrappers" available for those environments (nodejs, powershell) that make it pretty simple to call the Apigee Edge Admin API from a program built on them.

But you could also do it in a bash script, or a java program, or python if that's your bag. It's not that hard.

When serialized to json, a developer app entity looks like this:

{
  "apiProducts": [],
  "appFamily": "default",
  "appId": "1dec3225-32b2-4b57-b2d6-5d03e1f472e5",
  "attributes": [
    {
      "name": "DisplayName",
      "value": "QuotaApp"
    },
    {
      "name": "Attr1",
      "value": "abcde"
    }
  ],
  "callbackUrl": "",
  "createdAt": 1531759458431,
  "createdBy": "dchiesa@google.com",
  "credentials": [
    {
      "apiProducts": [
        {
          "apiproduct": "QuotaTestProduct",
          "status": "approved"
        }
      ],
      "attributes": [],
      "consumerKey": "Key-goes-here",
      "consumerSecret": "secret-goes-here",
      "expiresAt": 1534351459149,
      "issuedAt": 1531759459149,
      "scopes": [],
      "status": "approved"
    }
  ],
  "developerId": "c9e8411a-4a58-4127-a552-98e52960a422",
  "lastModifiedAt": 1531759458431,
  "lastModifiedBy": "dchiesa@google.com",
  "name": "QuotaApp",
  "scopes": [],
  "status": "approved"
}

What you want to do is grab all the apps in an organization (or maybe get all the apps for a particular product in an organization), and then in your code, filter that list to get only the apps that have a specific attribute that holds a particular value.

In Javascript this is super easy. It looks like this:

function getAppsWithAttribute( applist, attrName, attrValue) {
  var appIds = applist
    .filter( app =>
             app.attributes.find( attr => attr.name == attrName && attr.value == attrValue ))
    .map( app => app.appId );
  return appIds;
}

var apps1 = getAppsWithAttribute( allApps, "Attr1", "abcde");
console.log(JSON.stringify(apps1));

In Powershell, something like this:

$theApps = @( $FullList |? {
               $_.attributes |? { 
                 $_.name -eq $AttrName -and $_.value -eq $AttrValue 
               }
            })

In Bash you have to be a little more careful about how you parse the json. You could use jq or some other mechanism to help with that.

Does this help?