How do you find what Product a proxy is in?

If I look from a Product perspective, I can see what API proxies are assigned/included, but if I know what proxy I want to use, but I don't know the product associated with it, how do I quickly find the product(s) associated with the proxy without going to the product page and looking at each?

Solved Solved
2 4 2,307
1 ACCEPTED SOLUTION

I think you cannot do it within the Administrative User Interface, although I can see this would be a nice feature to have.

You can do it using the Administrative API; basically you'd search through the list of API Products and determine which ones have the API Proxy in question.

This is the admin API you must call. I do not think there is a limit to the number of API products it will return. (If there is a limit, it is not documented).

You can apply the expand=true query param to get all details of the API Product, then filter that list for the API products that have your proxy as a member of the "proxies" property. In nodejs, it looks like this:

// findProxy.js
// ------------------------------------------------------------------
//
// created: Mon Mar 20 09:57:02 2017
// last saved: <2017-March-20 10:06:17>


var request = require('request');
var mgmtserver = 'https://api.enterprise.apigee.com';
var org = 'cap500';
var readlineSync = require('readline-sync');
var username = readlineSync.question(' Edge User Name  : ');
var password = readlineSync.question(' Password for '+ username + ' : ',
                                     {hideEchoBack: true});
var requestOptions = {
      headers : { accept: 'application/json' },
      auth : {
        user: username,
        pass: password,
        sendImmediately : true
      }};


var url = mgmtserver + '/v1/o/' + org + '/apiproducts?expand=true';


request.get(url,
            requestOptions,
            function (error, response, body) {
              var result;
              if (error) {
                console.log(error);
              }
              else if (response.statusCode == 200) {
                processApiProducts(JSON.parse(body));
              }
              else {
                console.log('status: ' + response.statusCode );
              }
            });

var apiproxyOfInterest = 'java-props';

function processApiProducts (response) {
  var apiproducts = response.apiProduct;
  console.log('count of products: %d', apiproxyOfInterest, apiproducts.length);
  var filtered = apiproducts.filter(function(product) {
        return (product.proxies.indexOf(apiproxyOfInterest) >= 0);
      });


  console.log('count of products containing %s: %d', apiproxyOfInterest, filtered.length);
  console.log(JSON.stringify(filtered));
}

Update: here's a github link with working code.

You can also do this in Powershell, using the Edge powershell module. Here's an example of what that looks like:

Write-Output "Find API Product for a given API Proxy"


$Org = Read-Host "Edge org?"
$User = Read-Host "Edge admin user?"  # eg, 'dchiesa@google.com'
$SecurePass = Read-Host -assecurestring "Password"
$EncryptedPassword = ConvertFrom-SecureString $SecurePass


$connection = @{
   Org = $Org
   User = $User
   EncryptedPassword = $EncryptedPassword
}


Set-EdgeConnection @connection


$proxyToFind = Read-Host "Proxy to find"


$prods = @(Get-EdgeApiProduct -Params @{ expand = 'true' }).apiProduct
Write-Output ("Total Products: " + $prods.count)


$filteredProds = $prods |? { $_.proxies -contains $proxyToFind }


Write-Output ([string]::Format('Products: {0}', (ConvertTo-Json $filteredProds) ) )


And you can use any other scripting language, of course.

View solution in original post

4 REPLIES 4

I think you cannot do it within the Administrative User Interface, although I can see this would be a nice feature to have.

You can do it using the Administrative API; basically you'd search through the list of API Products and determine which ones have the API Proxy in question.

This is the admin API you must call. I do not think there is a limit to the number of API products it will return. (If there is a limit, it is not documented).

You can apply the expand=true query param to get all details of the API Product, then filter that list for the API products that have your proxy as a member of the "proxies" property. In nodejs, it looks like this:

// findProxy.js
// ------------------------------------------------------------------
//
// created: Mon Mar 20 09:57:02 2017
// last saved: <2017-March-20 10:06:17>


var request = require('request');
var mgmtserver = 'https://api.enterprise.apigee.com';
var org = 'cap500';
var readlineSync = require('readline-sync');
var username = readlineSync.question(' Edge User Name  : ');
var password = readlineSync.question(' Password for '+ username + ' : ',
                                     {hideEchoBack: true});
var requestOptions = {
      headers : { accept: 'application/json' },
      auth : {
        user: username,
        pass: password,
        sendImmediately : true
      }};


var url = mgmtserver + '/v1/o/' + org + '/apiproducts?expand=true';


request.get(url,
            requestOptions,
            function (error, response, body) {
              var result;
              if (error) {
                console.log(error);
              }
              else if (response.statusCode == 200) {
                processApiProducts(JSON.parse(body));
              }
              else {
                console.log('status: ' + response.statusCode );
              }
            });

var apiproxyOfInterest = 'java-props';

function processApiProducts (response) {
  var apiproducts = response.apiProduct;
  console.log('count of products: %d', apiproxyOfInterest, apiproducts.length);
  var filtered = apiproducts.filter(function(product) {
        return (product.proxies.indexOf(apiproxyOfInterest) >= 0);
      });


  console.log('count of products containing %s: %d', apiproxyOfInterest, filtered.length);
  console.log(JSON.stringify(filtered));
}

Update: here's a github link with working code.

You can also do this in Powershell, using the Edge powershell module. Here's an example of what that looks like:

Write-Output "Find API Product for a given API Proxy"


$Org = Read-Host "Edge org?"
$User = Read-Host "Edge admin user?"  # eg, 'dchiesa@google.com'
$SecurePass = Read-Host -assecurestring "Password"
$EncryptedPassword = ConvertFrom-SecureString $SecurePass


$connection = @{
   Org = $Org
   User = $User
   EncryptedPassword = $EncryptedPassword
}


Set-EdgeConnection @connection


$proxyToFind = Read-Host "Proxy to find"


$prods = @(Get-EdgeApiProduct -Params @{ expand = 'true' }).apiProduct
Write-Output ("Total Products: " + $prods.count)


$filteredProds = $prods |? { $_.proxies -contains $proxyToFind }


Write-Output ([string]::Format('Products: {0}', (ConvertTo-Json $filteredProds) ) )


And you can use any other scripting language, of course.

@Dino

Thank you for a useful tool. I was trying both the nodejs and powershell options and getting below errors. Can you please take a look?

Powershell - After org name, user name, pass and, proxy name is entered

"Set-EdgeConnection : The term 'Set-EdgeConnection' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At C:\git\apigee\utilities\EdgeTools\findProxy.ps1:17 char:1

+ Set-EdgeConnection @connection

+ ~~~~~~~~~~~~~~~~~~

+ CategoryInfo : ObjectNotFound: (Set-EdgeConnection:String) [], CommandNotFoundException

+ FullyQualifiedErrorId : CommandNotFoundException

Proxy to find: Utility-SMC-CORE-v1

Get-EdgeApiProduct : The term 'Get-EdgeApiProduct' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At C:\git\apigee\utilities\EdgeTools\findProxy.ps1:23 char:12

+ $prods = @(Get-EdgeApiProduct -Params @{ expand = 'true' }).apiProduct

+ ~~~~~~~~~~~~~~~~~~

+ CategoryInfo : ObjectNotFound: (Get-EdgeApiProduct:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException

Total Products: 0

Exception calling "Format" with "2" argument(s): "Value cannot be null.

Parameter name: args"

At C:\git\apigee\utilities\EdgeTools\findProxy.ps1:30 char:1

+ Write-Output ([string]::Format('Products: {0}', (ConvertTo-Json $filteredProds) ...

+~~~~~~~~~~~~~~~~~~~~

+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException

+ FullyQualifiedErrorId : ArgumentNullException"

=======================================================================

findApiProductForProxy.js - after user name and pass is entered

"You must specify an Edge organization

Usage: node findApiProductForProxy.js"

hi.

This is a new question

Can you please click the "Ask a Question" button to post this question?

I'll answer there.

5405-ask-a-question.png

Thanks for the complete answer. Code and links, like it!