I have checked the code provided previously , here is the tried and tested code which is working :
add_filter( 'bp_course_api_get_user_course_status_item',function($return, $request ){
$body = json_decode($request->get_body(),true);
if(!empty($body['token']) && is_numeric($request['course'])){
$user = apply_filters('vibebp_api_get_user_from_token','',$body['token']);
$user_id = $user->id;
}
if(!empty($user_id)){
//do your thing here and add the content to :
ob_start();
echo 'your dynamic content';
$cont = ob_get_clean();
$return['content'] .= $cont;//here the content is appending in api call return
}
return $return;
},10,2);