Importing entity reference data from the Drupal JSON:API to a separate Drupal site using the Migration system

Created on 14 June 2024, 7 months ago

I am setting up a system where one Drupal site serves as a Canonical source for specific content for a group of other Drupal sites to import from. I wanted to use the built-in Drupal JSON:API and Drupal Migration system to do this, but have had trouble figuring out how to properly import entity reference fields.

The Drupal JSON:API returns entity reference field data from a node as a relationship data set. It does not include the data for the entity referenced, just a separate API URL to request the date. For example an image reference returns this:

"relationships": {
        "news_banner": {
          "data": null,
          "links": {
            "related": {
              "href": "SITEURL/jsonapi/node/news/69f1dfc0-5f83-4bfc-9520-1688782cfb12/news_banner?resourceVersion=id%3A40756"
            },
            "self": {
              "href": "SITEURL/jsonapi/node/news/69f1dfc0-5f83-4bfc-9520-1688782cfb12/relationships/news_banner?resourceVersion=id%3A40756"
            }
          }
        },

From what I have found, the Drupal Migration System nor the migrate_plus module have an out of the box method to make sub-requests as part of the original migration. The JSON:API nor the jsonapi_extras module have an out of the box method to return the data for referenced entities/relationships as part of the request.

The method I've seen documented for the Migration System is to chain multiple migrations together β†’ . This method uses a separate migration to pull the entities referenced later and then link them back to the parent entity using a migration_lookup plugin. However, this method does not have a means to pull only the referenced entities you need to pull. It does not seem intended to run sub-requests from a previous migration to "fill in the blanks", but to migrate ALL data from a source and link the data together.

Am I missing something? Is there a way to do a sub-request as part of a Drupal Migration or to expose referenced entity data as part of a single JSON:API request? I am looking for an out of the box solution or a possible contrib module, and not having to write custom code to facilitate this.

I am tempted to just create a View that returns the JSON data required with Contextual Filters to allow filtering of the response. But I was hoping Drupal Core would have an out of the box solution for this type of data transfer between multiple Drupal instances.

πŸ’¬ Support request
Status

Active

Version

10.3 ✨

Component
MigrationΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States joegl

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024