This module allows you to migrate data from Drupal's JsonAPI by automatically handling pagination. It generates all necessary API requests to retrieve all items, even when there are many, by dynamically adjusting the page offset until all data is fetched.
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]".
Ask your assistant about Migration Jsonapi
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.