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.
-
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 );
-
Hi Timo,
At first glance your code looks correct. Could you try enable debugging please and share the output? http://podio.github.io/podio-php/debug/
Thanks!
-
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 );
-
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.
-
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 );
-
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?
-
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 );
-
Here a source code ready for developer: https://www.csvxlsvisualmapping.com/
Please sign in to leave a comment.
Comments
19 comments