How do I find the role id from role name? On log in I want to check a third party data source (table in the db) for a user, and if found I want to add a role to that user.

I don't want to guess the rid of the role, I want to get it from the role name.
Knowing the machine name of the role, it is enough to use user_role_load_by_name().

if ($role = user_role_load_by_name('Role Name')) {
  // The role ID is in $role-&gt;rid.
}


If the Role might not exist...

$role = user_role_load_by_name('Role Name');

$role_id = $role ? $role-&gt;rid : NULL;