How to add Drupal hook in developer portal to call external rest api on app registration

Not applicable

I want to call a rest service exposed from my system to register the application related information in my system when a developer registers an app in developer portal.

Can this be doable using a drupal hook?

Is it available in free cloud version?

Solved Solved
0 5 621
2 ACCEPTED SOLUTIONS

Dear @Gayan Shyamal ,

Yes, It's available in free cloud version. You can find details regarding same in 'devconnect_developer_apps' module "devconnect_developer_apps.api.php" file. Below are the hooks that you can use to call your rest service.

/**
 * Alter, augment or take other action right before a dev app is saved.
 *
 * If you do something to the developer_app entity in an implementation of this
 * hook such as deleting it, you should return FALSE here.
 *
 * @param $form_state (array)
 *   consists of $form_state from devconnect_developer_apps_edit_form
 * @return bool
 *   If the boolean value of FALSE is returned, further processing in saving the
 *   developer app is aborted. Any other value (including NULL, zero or the
 *   empty string) will allow save to continue.
 */
function hook_devconnect_developer_app_presave(array &$form_state) {
  $form_state['values']['attribute_drupal_uid'] = $form_state['values']['uid'];
  return TRUE;
}


/**
 * Take some action right after a developer app is saved.
 *
 * If you do something to the developer_app entity in an implementation of this
 * hook such as deleting it, you should return FALSE here.
 *
 * @param $results (associative array returned from KMS)
 * @param $form_state (array)
 *   consists of $form_state from devconnect_developer_apps_edit_form.
 *   $form_state['storage']['entity'] holds the developer_app entity.
 * @return bool
 *   If any value other than FALSE is returned (including NULL or no value at
 *   all), further processing in saving the developer app is aborted.
 */
function hook_devconnect_developer_app_save(array $results, array &$form_state) {
  $form_state['redirect'] = '<front>';
  return TRUE;
}


View solution in original post

Not applicable

Hi @Gayan Shyamal

Welcome to Apigee Community.

We do have hooks before & after the app is being created.

/**
 * Alter, augment or take other action right before a dev app is saved.
 *
 * If you do something to the developer_app entity in an implementation of this
 * hook such as deleting it, you should return FALSE here.
 *
 * @param $form_state (array)
 *   consists of $form_state from devconnect_developer_apps_edit_form
 * @return bool
 *   If the boolean value of FALSE is returned, further processing in saving the
 *   developer app is aborted. Any other value (including NULL, zero or the
 *   empty string) will allow save to continue.
 */
function hook_devconnect_developer_app_presave(array &$form_state) {
  $form_state['values']['attribute_drupal_uid'] = $form_state['values']['uid'];
  return TRUE;
}


/**
 * Take some action right after a developer app is saved.
 *
 * If you do something to the developer_app entity in an implementation of this
 * hook such as deleting it, you should return FALSE here.
 *
 * @param $results (associative array returned from KMS)
 * @param $form_state (array)
 *   consists of $form_state from devconnect_developer_apps_edit_form.
 *   $form_state['storage']['entity'] holds the developer_app entity.
 * @return bool
 *   If any value other than FALSE is returned (including NULL or no value at
 *   all), further processing in saving the developer app is aborted.
 */
function hook_devconnect_developer_app_save(array $results, array &$form_state) {
  $form_state['redirect'] = '<front>';
  return TRUE;
}

Please take a look at the above hooks, you should be good to extend them in your custom module.

View solution in original post

5 REPLIES 5

Dear @Gayan Shyamal ,

Yes, It's available in free cloud version. You can find details regarding same in 'devconnect_developer_apps' module "devconnect_developer_apps.api.php" file. Below are the hooks that you can use to call your rest service.

/**
 * Alter, augment or take other action right before a dev app is saved.
 *
 * If you do something to the developer_app entity in an implementation of this
 * hook such as deleting it, you should return FALSE here.
 *
 * @param $form_state (array)
 *   consists of $form_state from devconnect_developer_apps_edit_form
 * @return bool
 *   If the boolean value of FALSE is returned, further processing in saving the
 *   developer app is aborted. Any other value (including NULL, zero or the
 *   empty string) will allow save to continue.
 */
function hook_devconnect_developer_app_presave(array &$form_state) {
  $form_state['values']['attribute_drupal_uid'] = $form_state['values']['uid'];
  return TRUE;
}


/**
 * Take some action right after a developer app is saved.
 *
 * If you do something to the developer_app entity in an implementation of this
 * hook such as deleting it, you should return FALSE here.
 *
 * @param $results (associative array returned from KMS)
 * @param $form_state (array)
 *   consists of $form_state from devconnect_developer_apps_edit_form.
 *   $form_state['storage']['entity'] holds the developer_app entity.
 * @return bool
 *   If any value other than FALSE is returned (including NULL or no value at
 *   all), further processing in saving the developer app is aborted.
 */
function hook_devconnect_developer_app_save(array $results, array &$form_state) {
  $form_state['redirect'] = '<front>';
  return TRUE;
}


Thanks Anil.

Is this done using the Pantheon Dashboard? I can't see any other means to find this devconnect_developer_apps.api.php file.

I still dont have access to the Pantheon Dashboard

Best regards

Shyamal

Hi @Gayan Shyamal

Please feel free to raise a request with Apigee support, they should be able to help with the access to your instance.

Not applicable

Hi @Gayan Shyamal

Welcome to Apigee Community.

We do have hooks before & after the app is being created.

/**
 * Alter, augment or take other action right before a dev app is saved.
 *
 * If you do something to the developer_app entity in an implementation of this
 * hook such as deleting it, you should return FALSE here.
 *
 * @param $form_state (array)
 *   consists of $form_state from devconnect_developer_apps_edit_form
 * @return bool
 *   If the boolean value of FALSE is returned, further processing in saving the
 *   developer app is aborted. Any other value (including NULL, zero or the
 *   empty string) will allow save to continue.
 */
function hook_devconnect_developer_app_presave(array &$form_state) {
  $form_state['values']['attribute_drupal_uid'] = $form_state['values']['uid'];
  return TRUE;
}


/**
 * Take some action right after a developer app is saved.
 *
 * If you do something to the developer_app entity in an implementation of this
 * hook such as deleting it, you should return FALSE here.
 *
 * @param $results (associative array returned from KMS)
 * @param $form_state (array)
 *   consists of $form_state from devconnect_developer_apps_edit_form.
 *   $form_state['storage']['entity'] holds the developer_app entity.
 * @return bool
 *   If any value other than FALSE is returned (including NULL or no value at
 *   all), further processing in saving the developer app is aborted.
 */
function hook_devconnect_developer_app_save(array $results, array &$form_state) {
  $form_state['redirect'] = '<front>';
  return TRUE;
}

Please take a look at the above hooks, you should be good to extend them in your custom module.

Please provide the steps and examples it will be helpful for how to invoke the external URL