This project is not covered by Drupal’s security advisory policy.

This module extends the Migrate Plus, Json Parser to interact with Drupal's JsonAPI.

When interacting with Drupal's JsonAPI there is a limit to the number of results that will be delivered. To get all results you have to make several requests, each time adjusting the page offset.

The Json Parser supplied with Migrate Plus requires the url parameter to supply an array of urls to query. But we do not know how many urls are needed to get all results.

Rather than supplying the migration source an array of urls, the JsonAPI parser will generate all urls necessary for the migration. This is done by supplying the JsonAPI parser the parameters necessary to construct the urls and adjust the offset value each time.

Example usage:

source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: jsonapi
  item_selector: data
  jsonapi_host: {source host}
  jsonapi_prefix: '/jsonapi'
  jsonapi_endpoint: '/node/article'
  jsonapi_query_params:
    filter:
      default_langcode: 0
  jsonapi_langcodes:
    - ja
    - de
  urls: []

This will generate the following urls:

  • {source host}/ja/jsonapi/node/article?filter[default_langcode]=0&page[limit]=50&page[offset]=0
  • {source host}/ja/jsonapi/node/article?filter[default_langcode]=0&page[limit]=50&page[offset]=50
  • {source host}/ja/jsonapi/node/article?filter[default_langcode]=0&page[limit]=50&page[offset]=100
  • ...
  • {source host}/de/jsonapi/node/article?filter[default_langcode]=0&page[limit]=50&page[offset]=0
  • {source host}/de/jsonapi/node/article?filter[default_langcode]=0&page[limit]=50&page[offset]=50
  • {source host}/de/jsonapi/node/article?filter[default_langcode]=0&page[limit]=50&page[offset]=100
  • ...

The "page[offset]" parameter will increment by the "page[limit]" parameter value. until an empty result is returned.

By default these parameters are configured to work with Drupal's JsonAPI, but the names of these parameters can also be adjusted

source:
  jsonapi_query_param_keys:
    page_offset: 'offset'
    page_limit: 'items_per_page'
  prepend_langcode: FALSE

With the above example the query parameter for the page_offset will now be "offset" instead of "page[offset]".

Project information

  • caution Minimally maintained
    Maintainers monitor issues, but fast responses are not guaranteed.
  • Project categories: Import and export
  • Ecosystem: Migrate Plus
  • Created by mcalabrese on , updated
  • shield alertThis project is not covered by the security advisory policy.
    Use at your own risk! It may have publicly disclosed vulnerabilities.

Releases