1

I'm working with a live stock API and want to import the products on a daily basis (using a cron job probably). At this moment I've setup a Feed Me feed as entries. This works for all products where the data is presented one by one. But the data does also have a part with an array and inside that array also columns, arrays like this:

{
   "supplier_data_columns": ["value1", "value2", "value3" {
    "properties": {
      "203": "width_package",
      "205": "height_package",
      "206": "length_package"
    }
  }]
}

This is then used in the article descriptions:

"supplier_data": [
      ["F.15852", "Scott", "2557" {
      "203": "50",
      "205": "40",
      "206": "100"
      }]

How do I address this? Is this even possible with Feed Me? Do I need to import the whole array at once as "supplier data" and then extract the right columns in the entry? Or is a module needed here?

1 Answer 1

1

Maybe I didn't fully understand you... But, I think what you need is to make your own module and hook the event from FeedMe.

    use craft\feedme\services\Process;
    use craft\feedme\events\FeedProcessEvent;
    use craft\feedme\events\FeedDataEvent;
    use craft\feedme\services\DataTypes;
    use craft\elements\Entry;

Event::on(DataTypes::class, DataTypes::EVENT_AFTER_PARSE_FEED, static function (FeedDataEvent $event): void {
   if (!$event->response['success']) {
      return;
   }

   $data = $event->response['data'];
   // .. Deal with data here, e.g. parse correctly JSON or change it
}

Or probably something like that

Event::on(Process::class, Process::EVENT_STEP_AFTER_ELEMENT_SAVE, function (FeedProcessEvent $event) {
    $myEntry = $event->element;
    // ... Change your JSON structure or do what you want after element saved
}
2
  • Okay so the right thing to do would be to change the JSON data so that it will be workable for Feed Me. I'll look into it.
    – noregt
    Commented Jul 7, 2022 at 7:19
  • 1
    I've had success with pasting JSON data into a string variable into Chrome's console, then using JavaScript to manipulate the data to turn it into a format that's easier to use with Feed Me. Lots of .map() to get the data into more consistent formats! Once it's right, you can copy it out from the console and paste into a JSON file to use with Feed Me. Commented Jul 7, 2022 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.