Skip to content
40 changes: 40 additions & 0 deletions redcap/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,46 @@ def export_fem(self, arms=None, format='json', df_kwargs=None):

return self.read_csv(StringIO(response), **df_kwargs)

def export_field_names(self, field=None, format='json', df_kwargs=None):
"""
Export the project's export field names

Parameters
----------
fields : str
Limit exported field name to this field (only single field supported).
When not provided, all fields returned.
format : (``'json'``), ``'csv'``, ``'xml'``, ``'df'``
Return the metadata in native objects, csv or xml.
``'df'`` will return a ``pandas.DataFrame``.
df_kwargs : dict
Passed to ``pandas.read_csv`` to control construction of
returned DataFrame.
by default ``{'index_col': 'original_field_name'}``

Returns
-------
metadata : list, str, ``pandas.DataFrame``
metadata structure for the project.
"""
ret_format = format
if format == 'df':
ret_format = 'csv'

pl = self.__basepl('exportFieldNames', format=ret_format)

if field:
pl['field'] = field

response, _ = self._call_api(pl, 'exp_field_names')

if format in ('json', 'csv', 'xml'):
return response
elif format == 'df':
if not df_kwargs:
df_kwargs = {'index_col': 'original_field_name'}
return self.read_csv(StringIO(response), **df_kwargs)

def export_metadata(self, fields=None, forms=None, format='json',
df_kwargs=None):
"""
Expand Down
2 changes: 2 additions & 0 deletions redcap/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def validate(self):
valid_data = {
'exp_record': (['type', 'format'], 'record',
'Exporting record but content is not record'),
'exp_field_names': (['format'], 'exportFieldNames',
'Exporting field names, but content is not exportFieldNames'),
'del_record': (['format'], 'record',
'Deleting record but content is not record'),
'imp_record': (['type', 'overwriteBehavior', 'data', 'format'],
Expand Down