I need to do a REST request every time a new user signs up.

The REST request returns some data that I need to store for the Drupal user account, and be able to present as content somewhere.

What is the best/cleanest way to do that?

  • Please specify the used Drupal version. – Pierre Buyle Nov 9 '11 at 13:06

You can do it in a simple custom module, be sure to first understand Drupal hooks system as this is the base for (almost) everything Drupal.

In your module, you can implement hook_user_presave() to be called before a user account is saved. It will be called for both creation and update, so you will need to guard your code with a condition to detect new user. After the REST call, there is several option to store the returned data. The easiest one is the use the data attribute of the user account. It is a simple PHP array that will be serialized in a database columns. It is not very good performande wise and not very flexible (you can query the stored data) but it is easy.

function MODULE_user_presave(&$edit, $account, $category) {
  // Accoding to user_save's documentation, this is a new user if
  // $account->is_new is set to TRUE or if $account->uid is not set
  if ($category == 'account' && (!empty($account->is_new) || !isset($account->uid)))) {
    $edit['data']['MODULE'] = MODULE_get_data_from_rest($account);

A core feature in Drupal 7 is available that can trigger a specific action if a user is created, etc. You don't have to code to achieve this:

  • Enable the module Triggers
  • Go to Configuration >> Actions and create an action available on the dropdown list
  • Go to Structure >> Triggers, click on the User tab and assign the action you created awhile back to Trigger: After creating a new user account
  • Yep, but there is no "do a REST request and store the result in the user account" action. – Pierre Buyle Nov 9 '11 at 13:03

The Rules or Workflow modules may be what you are looking for.

  • Rules could be used with it, but the REST request still need to be coded in PHP. And workflow has no use here. – Pierre Buyle Nov 9 '11 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.