Rest API code to get ID of current user not working: get_current_user_id() gives 0

Rest API code to get ID of current user not working: get_current_user_id() gives 0