Get Custom Field value with Python Search API

Hello all,

I’m trying to use the Search API with Python to make an advanced search. I managed to do a search but I want to obtain one specific Custom Field but no matter how I do it, I can’t. I tried using custom_fields.enum_value, text_value, and so on (the field is supposed to be a text field).

Here you have an example:

[{'gid': '1139247426380031', 'name': 'SUPPLIER'}, {'gid': '1139247426380041', 'name': 'Problem type'}, *{'gid': '1139247426380028', 'name': 'SKU Affected', 'text_value': None}**, {'gid': '1162394674904100', 'name': 'Courrier', 'text_value': None} , **{'gid': '1167068898757021', 'name': 'Courier', 'text_value': 'UPS, UPS'}**, {'gid': '1167051532424011', 'name': 'SKU 1', 'text_value': None},  {'gid': '1167051532424050', 'name': 'Replacement Shipping data', 'text_value': None}, {'gid': '1167051532424053', 'name': 'Order Date', 'text_value': None}]

As you can see, I get none for the Text Value (in bold) but not for the other one.

Here you can see the definition of the Custom Field

{'gid': '1139247426380028',
 'name': 'SKU Affected',
 'created_by': {'gid': 'XXXX',
  'name': 'XXXXX',
  'resource_type': 'user'},
 'resource_subtype': 'text',
 'resource_type': 'custom_field',
 'type': 'text',
 'is_global_to_workspace': True}

How could I get this value? I’m pretty new with the API but I’m stuck here.
Thank you so much in advance.

I said “in bold” but seems like code blocks can’t be bold. Still the related field is SKU Affected

Hi,

Can you share the params of your search request? You’ll have to ask for the right opt_fields…

Sure @Bastien_Siebman , I was playing around trying different options but they were like this

data = client.tasks.search_tasks_for_workspace(
        workspace_gid=WORKSPACE_GID,
        params={f'custom_fields.{SUPPLIER_FIELD_GID}.value':f'{SUPPLIER_GID}', 
                'created_on.after': '2020-02-15',
                'custom_fields.1139247426380041.value': PROB_TYPE_GID},
        opt_fields=['completed', 'name', 
                    'custom_fields.name', 
                    'custom_fields.text_value.name'], 
    
    )

I think I know. The fields you are querying don’t exist, look at Asana. No field “name” on “custom_fields” on tasks, and “text_value” is a string. So use custom_fields.text_value and that should work for text fields.

Let me know!

Omg, thanks @Bastien_Siebman, that solved the problem. I was pretty sure I tried that option before but seems like I didn’t.

My pleasure. I made the mistake of forgetting fields about a hundred times ^^what about you @Phil_Seeman ? :stuck_out_tongue:

Oh, for sure! Probably a thousand times.