Post

3 followers Follow
0
Avatar

Import field mapping code examples? (PHP)

I'm building an application that creates a CSV import to Podio via the API. I have some problems with field mappings (i.e. turns out I don't know how to do them).

Does anyone have any code examples on how to set the field mappings for Importer in PHP? Please share!

I'm especially interested in mapping relationship fields with multiple values. This means that my CSV has multiple values in one cell and they should form multiple references to another app in a single relationship field in the target app.

Timo Sillander

Please sign in to leave a comment.

18 comments

0
Avatar

Hi Timo,

What error are you seeing right now? Can you share the API call that is failing?

Thanks,
Andreas

Andreas Garnæs 0 votes
0
Avatar

Sorry for being vague.

Not really error, but what I got was that all the rows in my CSV were skipped and none imported.

Here's an example of the code I tried:

$attributes = array(
    'app_id' => $app_id,
    'mappings' => array(
        array(
            'field_id' => 102190506, // The field receiving multiple reference values
            'value' => array(
                'app_id' => 12476528, // The app to which the references should point to 
                'mappings' => array(
                    array(
                        'field_id' => 102190406, // The referenced item's title field
                        'value' => array(
                            'column_id' => 'References'
                        )
                    ) 
                )
            )
        )
    ),
    'app_item_id_column_id' => 'ID' // The id of the column to read the app item id from, if any
);
Timo Sillander 0 votes
1
Avatar

The documentation was a bit vague. I found out the reference to the column has to be the position of the column as a number starting from 0, given as a string for instance '0'.

I contacted support to get the importer doc page clarfied.

Henrik Huhtinen 1 vote
0
Avatar

Henrik is right. Here's the same code example in working order:

$attributes = array(
    'app_id' => $app_id,
    'mappings' => array(
        array(
            'field_id' => 102190506, // The field receiving multiple reference values
            'value' => array(
                'app_id' => 12476528, // The app to which the references should point to
                'mappings' => array(
                    array(
                        'field_id' => 102190406, // The referenced item's title field
                        'unique' => true,
                        'value' => array(
                            'column_id' => '1'
                        )
                    ) 
                )
            )
        )
    ),
    'app_item_id_column_id' => '0' // The id of the column to read the app item id from, if any
);
Timo Sillander 0 votes
0
Avatar

Another related question though, maybe Andreas could help:

Can we update the relation by just using the app_item_id_column and the unique id of the referenced item?

Mappings is a required field. I tried giving an empty array as mappings and defining app_item_id_column, but it seems to skip all rows then. When working with API using this would be handy.

Henrik Huhtinen 0 votes
0
Avatar

Henrik, just to make sure I understand the question, could you provide the JSON/PHP parameter you'd like to use?

Andreas Garnæs 0 votes
0
Avatar

I can do that:
here's what we'd like to do, but can't:

$attributes = array(
    'app_id' => $app_id,
    'mappings' => array(
        array(
            'field_id' => 102190506, // The field receiving multiple reference values
            'value' => array(
                'app_id' => 12476528, // The app to which the references should point to
                'mappings' => array(), // No mappings needed, we're referencing the items by ID
                'app_item_id_column_id' => '1' // Second column in CSV, with referenced items' IDs
            )
        )
    ),
    'app_item_id_column_id' => '0' // The id of the column to read the app item id from, if any
);
Timo Sillander 0 votes
0
Avatar

Timo, I can see how that could make sense. I'll forward the request to the team. Thanks for the feedback :)

Andreas Garnæs 0 votes
0
Avatar

Just make sure: does that mean that it is in fact impossible to do this currently?

In other words: is our only solution to update some other field at the same time?

Timo Sillander 0 votes
0
Avatar

Just make sure: does that mean that it is in fact impossible to do this currently?

What do you mean by "this" exactly?

Andreas Garnæs 0 votes
0
Avatar

Sorry of I was vague;

I meant: does your answer mean that with the currently available API features it's impossible to create an import job that imports items with multiple relationship field references in a single field pointing to another app without updating fields in relationship target items in that app?

Timo Sillander 0 votes
0
Avatar

With the attributes you showed earlier (see below), the related items won't actually be updated: the title field (field id 102190406) will only be used for finding an existing item with that title (if such one should exist). You can have multiple values in the relationship field by separating with semicolon (try setting up two dummy apps with a relationship field, an item with two values in the relationship field and then do an export).

$attributes = array(
    'app_id' => $app_id,
    'mappings' => array(
        array(
            'field_id' => 102190506, // The field receiving multiple reference values
            'value' => array(
                'app_id' => 12476528, // The app to which the references should point to
                'mappings' => array(
                    array(
                        'field_id' => 102190406, // The referenced item's title field
                        'unique' => true,
                        'value' => array(
                            'column_id' => '1'
                        )
                    ) 
                )
            )
        )
    ),
    'app_item_id_column_id' => '0' // The id of the column to read the app item id from, if any
);
Andreas Garnæs 0 votes
0
Avatar

Sorry Andreas I do not understand. In my opinion the 'value' => array('column_id' => '1') exactly updates the value of the referenced field instead of matching it.

Henrik Huhtinen 0 votes
0
Avatar

Thanks Andreas, that's interesting. Is there a way to match against app_item_id instead of title, as in the example above?

Timo Sillander 0 votes
0
Avatar

Timo, unfortunately not, but I think it's a very valid use case. As mentioned, I'll forward the request to the team :)

Andreas Garnæs 0 votes
0
Avatar

Thanks for the reply. At least now we know our solution is the best possible for now. And it works – which is the main thing, naturally.

Timo Sillander 0 votes