Import field mapping code examples? (PHP)

Comments

19 comments

  • Andreas Garnæs

    Hi Timo,

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

    Thanks,
    Andreas

    0
    Comment actions Permalink
  • Timo Sillander

    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
    );
    
    0
    Comment actions Permalink
  • Andreas Garnæs

    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!

    0
    Comment actions Permalink
  • Henrik Huhtinen

    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.

    1
    Comment actions Permalink
  • Timo Sillander

    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
    );
    
    0
    Comment actions Permalink
  • Henrik Huhtinen

    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.

    0
    Comment actions Permalink
  • Andreas Garnæs

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

    0
    Comment actions Permalink
  • Timo Sillander

    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
    );
    
    0
    Comment actions Permalink
  • Andreas Garnæs

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

    0
    Comment actions Permalink
  • Timo Sillander

    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?

    0
    Comment actions Permalink
  • Andreas Garnæs

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

    What do you mean by "this" exactly?

    0
    Comment actions Permalink
  • Timo Sillander

    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?

    0
    Comment actions Permalink
  • Andreas Garnæs

    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
    );
    
    0
    Comment actions Permalink
  • Henrik Huhtinen

    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.

    0
    Comment actions Permalink
  • Andreas Garnæs

    Henrik, if you include 'unique' => true then it will be used for matching.

    0
    Comment actions Permalink
  • Timo Sillander

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

    0
    Comment actions Permalink
  • Andreas Garnæs

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

    0
    Comment actions Permalink
  • Timo Sillander

    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.

    0
    Comment actions Permalink
  • ZaGoox

    Here a source code ready for developer: https://www.csvxlsvisualmapping.com/

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk