+1
Under review
Export custom user fields
Does anyone know how to export the custom fields that we are adding when our users register. I see the data on the Custom tab of the users' accounts, but when I export the users to a csv file the only fields that are exported are
screenname | account_type | firstname | lastname | createtime | authtime | country | address | municipality | region | postcode | phone | gender | birthday |
There's nothing in the TN documentation about this. The documentation tells you how to add a custom field to the registration form, but it's not much good if we can't export that information.
Customer support service by UserEcho
Hi Maureen,
Where you able to figure this out? We too would like better data exporting and ways to enrich our data.
We currently use Airtable and Zaiper. We are going to see if we can setup a webhook to update records this way. Please let me know if you figure out a solution to your original question.
I found a way, using the API calls. When you pull a user account info, it has a "custom" array that has your custom items in it.
Are pulling the information for all of your users with the API calls? I've used it to get a single user's custom fields when they get to particular page, but I haven't found a way to get the information for all users in one export. For example, we used a custom field to save a subscriber's high score for a javascript game. When that user comes back to the game, the score is shown. But I don't know how to get a list of all of the users that have saved high scores. If I could see all of the users that have a value set in that field, I would know how many of them played the game.
I use a function to grab all info for a subscriber. I loop through all of our user, pulling each in and check their custom variable (in my case circid). The function that pulls in a specific user pulls in all information, subscription, login, services, etc. I use it for any user information lookup I need so it is fairly generic. Once you have the screen name, or email address as a search item you can then pull in their entire record and check any of the fields you want. Just remember that you have to check for a "lack of variable' when looking at custom values.
The code below is old, and was used while I was testing and learning the Townnews API. Bug are mine, but this code does work in 90+% of the time. Error checking was at a minimum at this point.
Call to function:
$sub_arr=get_user_info($user);
Check for 'customer' field (circid is an internal customer id number for one of our tools):
if(isset($sub_arr['custom']['circid'])&&$sub_arr['custom']['circid']!=0) {
//do doemthing
} else {
//do something else
}
function:
function get_user_info($user_id) {
//$user_id == screenname or email address
$user_arr=array();
$result_arr=process_command("user","get",array('user'=>"$user_id"));
$services_array=get_services();
$serv_arr=process_command("subscription","get_user_services",array('user'=>"$user_id"));
if(!isset($result_arr['error_code'])) {
$user_arr=$result_arr;
$user_arr['services']=$serv_arr;
$user_arr['error']=0;
$user_arr['message']="";
} else {
//handle error condition
$user_arr['error']=1;
$user_arr['message']="Error detected. Error is ".print_r($result_arr['error_code'],true)." \r\n";
}
$user_arr=$result_arr;
$user_arr['services']=array();
foreach($serv_arr as $service_id) {
if($service_id>0) {
$resultserv_arr=array();
$user_arr['services'][$service_id]['name']=$services_array[$service_id]['name'];
for($i=0; $i<100; $i++) {
$resultserv=process_command("subscription","search",
array('page'=>$i,'limit'=>100,'user_email'=>$user_id,'service_ids'=>$service_id));
if(!isset($resultserv[1])) {
$i=999999;
}
foreach($resultserv AS $item) {
if(trim($item['user_uuid'])==trim($user_arr['id'])) {
if(trim($item['id'])!= "") {
$user_arr['services'][$service_id]['id']=$item['id'];
$user_arr['services'][$service_id]['serviceID']=$service_id;
} else {
$user_arr['services'][$service_id]['id']="0";
}
}//end if(trim($item['user_uuid']...
}//endforeach
}//endfor($i=0...
}//endif($service_id>0)...
}//endforeach($serv_arr...
if($result_arr['is_admin']==1) {
$user_arr['services'][99999]['name']="Admin access";
$user_arr['services'][99999]['serviceID']=99999;
$user_arr['services'][99999]['id']=0;
}
if(isset($user_arr['service'][0]) && is_array($user_arr['service'][0])) { unset($user_arr['service'][0]); }
return $user_arr;
}
Sort of. I use a PHP script to pull a list of subscribers/users then loop through that to download the individual subscriber information. Pulls about 1000 entries every 3-4 minutes, but I get everything about them that way. I don't run it often, but when I need a complete list, this is how I do it.