APIs to get app id and developer details

We(Plantronics) are creating a developer portal for our Cloud APIs. But, we have our own SaaS web app on which we need some of the data from the developer portal (AppName, id, API keys, developer profile information etc.) needs to be integrated. How to get, update etc. using APIs from dev portal admin data ?

Next, when a developer registers and creates an app - We want to call our internal APIs to persist this information for our own cloud for using in our internal buss logic. Is there a way to add these extra customization in the app creation/dev registration flow ?

Solved Solved
1 5 1,139
1 ACCEPTED SOLUTION

@manojramakrishnan ,

You need little bit of Drupal Expertise to do same. You need to understand how to implement hooks that are exposed by apigee.

For Example, when you go to file /profiles/apigee/modules/custom/devconnect/devconnect_developer_apps/devconnect_developer_apps.api.php files, you can see list of hooks exposed by the module.

For example, one of the hook is hook_devconnect_developer_app_save($results, &$form_state) which will get called whenever new developer app is created in portal. You can implement the hook in custom module & make an API call to your internal system.

Implementing a hook is fairly simple, see steps below.

  • A custom module in sites/all/modules/custom , let's call it plantronics_app_flow
  • Create a folder called plantronics_app_flow in sites/all/modules/custom
  • Create a file called plantronics_app_flow.info with below code,
name = Plantronics App Custom Workflow
description = Plantronics App Custom Workflow
core = 7.x
package = Plantronics Custom Module
  • Create a file called plantronics_app_flow.module with below code, which implements above hook. Implementing a hook is nothing but creating a function with module name instead of hook keyword.
function plantronics_app_flow_devconnect_developer_app_save(array $results, array &$form_state) {
    // Get App Details
    $app_id = $results['data']['appId'];
    $entities = entity_load('developer_app', array($app_id));
    $entity = reset($entities);
    // Extract app data needed
    drupal_set_message("<pre>" . print_r($entity, 1) . "</pre>");
    $client_id = $entity->credentials[0]['consumerKey'];
    $client_secret = $entity->credentials[0]['consumerSecret'];
    $app_name = $entity->name;
    $callback_url = $entity->callbackUrl;
    //Get the endpoint details..
    $server_endpoint = 'https://xxxxxxx';
    // Make the call to ping..
    $payload = '{  
   "client":[  
      {  
         "bypassApprovalPage":"true",
         "name":"' . $app_name .  '",
         "clientId":"'. $client_id .'",
         "secret":"' . $client_secret . '",
         "grantTypes":[  
            "authorization_code",
            "implicit",
            "client_credentials"
         ],
         "restrictScopes":"true",
         "restrictedScopes":[  
            "email",
            "openid",
            "profile"
         ],
         "redirectUris":["'. $callback_url .'"]
      }
   ]
}';
    $auth_header = base64_encode('xxxusername:xxxpassword');
    $options = array(
        'method' => 'POST',
        'data' => $payload,
        'timeout' => 15,
        'headers' => array('Content-Type' => 'application/json', 'Authorization' => 'Basic ' . $auth_header),
    );
    $result = drupal_http_request($server_endpoint, $options);
    drupal_set_message("<pre>" . print_r($result, 1) . "</pre>");
    return TRUE;
}

More about drupal_http_request here.

  • Go to admin/modules & enable above custom module you have created.
  • Create an app & see it in action.

Hope it helps. I would recommend get a resource with Drupal Expertise to do above workflows.

View solution in original post

5 REPLIES 5

Not applicable

Hi @manojramakrishnan , From your webapp, you can directly call the APIs that are mentioned here https://docs.apigee.com/api/apps-0 as all the developers and apps info is in Edge.

Regarding your second question, refer this http://docs.apigee.com/developer-services/content/communicating-between-developer-services-portal-an.... I haven't tried but you can route the calls to your internal APIs which can talk to Edge instead of directly calling Edge.

cc @Anil Sagar any thoughts

@manojramakrishnan ,

You need little bit of Drupal Expertise to do same. You need to understand how to implement hooks that are exposed by apigee.

For Example, when you go to file /profiles/apigee/modules/custom/devconnect/devconnect_developer_apps/devconnect_developer_apps.api.php files, you can see list of hooks exposed by the module.

For example, one of the hook is hook_devconnect_developer_app_save($results, &$form_state) which will get called whenever new developer app is created in portal. You can implement the hook in custom module & make an API call to your internal system.

Implementing a hook is fairly simple, see steps below.

  • A custom module in sites/all/modules/custom , let's call it plantronics_app_flow
  • Create a folder called plantronics_app_flow in sites/all/modules/custom
  • Create a file called plantronics_app_flow.info with below code,
name = Plantronics App Custom Workflow
description = Plantronics App Custom Workflow
core = 7.x
package = Plantronics Custom Module
  • Create a file called plantronics_app_flow.module with below code, which implements above hook. Implementing a hook is nothing but creating a function with module name instead of hook keyword.
function plantronics_app_flow_devconnect_developer_app_save(array $results, array &$form_state) {
    // Get App Details
    $app_id = $results['data']['appId'];
    $entities = entity_load('developer_app', array($app_id));
    $entity = reset($entities);
    // Extract app data needed
    drupal_set_message("<pre>" . print_r($entity, 1) . "</pre>");
    $client_id = $entity->credentials[0]['consumerKey'];
    $client_secret = $entity->credentials[0]['consumerSecret'];
    $app_name = $entity->name;
    $callback_url = $entity->callbackUrl;
    //Get the endpoint details..
    $server_endpoint = 'https://xxxxxxx';
    // Make the call to ping..
    $payload = '{  
   "client":[  
      {  
         "bypassApprovalPage":"true",
         "name":"' . $app_name .  '",
         "clientId":"'. $client_id .'",
         "secret":"' . $client_secret . '",
         "grantTypes":[  
            "authorization_code",
            "implicit",
            "client_credentials"
         ],
         "restrictScopes":"true",
         "restrictedScopes":[  
            "email",
            "openid",
            "profile"
         ],
         "redirectUris":["'. $callback_url .'"]
      }
   ]
}';
    $auth_header = base64_encode('xxxusername:xxxpassword');
    $options = array(
        'method' => 'POST',
        'data' => $payload,
        'timeout' => 15,
        'headers' => array('Content-Type' => 'application/json', 'Authorization' => 'Basic ' . $auth_header),
    );
    $result = drupal_http_request($server_endpoint, $options);
    drupal_set_message("<pre>" . print_r($result, 1) . "</pre>");
    return TRUE;
}

More about drupal_http_request here.

  • Go to admin/modules & enable above custom module you have created.
  • Create an app & see it in action.

Hope it helps. I would recommend get a resource with Drupal Expertise to do above workflows.

@Anil Sagar just curious, pointing to the local/internal endpoint which points to the management endpoint (like a passthrough for example)here Management API endpoint URL * under /admin/config/devconnect will not work?

Thanks @Anil Sagar for the detailed answer. I will take a look at it. Yes, we are requesting some Drupal experts to work with.


Awesome, Great to know. Keep us posted moving forward if any.