![]() The field_image field points to related images, and the uid/author field points to related users. This will display a JSON feed of all articles. The primary path used for our migration is (where is a valid site): http(s):///jsonapi/node/article It is important to note that if you alter the YAML files after you first install the module, you'll have to uninstall and then reinstall the module to get Migrate to see the YAML changes. Edit the YAML files in the /config/optional directory of that module to alter the JSON source URL so it points to the domain for the source site created in the earlier step. Download this module into your module repository. To make it easier, and so I don’t forget how I got this working, I created a migration example as the Import Drupal module on Github. ![]() Migrate Plus had 8.0 and 8.1 branches that only work with outdated versions of core, so currently you need version 8.2 of Migrate Plus. Make sure to get the versions that are appropriate for the current version of core. Download and enable the Migrate Plus and Migrate Tools modules. ![]() It should already have a matching article content type and field_image field ready to accept the articles from the other site.Įnable the core Migrate module. There are changes to the way file imports work that won't work in earlier versions. The target site should be running Drupal 8.2.3 or higher. Navigate to a URL like and confirm that JSON is being output at that URL. If using basic authentication and the Basic Auth module isn’t already enabled, enable it. You could also switch out the authentication to something like OAuth, but for this article we’ll stick with the built-in basic and cookie authentication methods. If you wanted to update or post content you’d add POST or PATCH information. That will support GET, or read-only access. To expose users or taxonomy terms or comments, copy the above file, and change the name and id as necessary, like this: filename: /MODULE/config/optional/_term.yml: id: entity.taxonomy_term For instance, if you created a module called custom_jsonapi, a file that would expose node data might look like: filename: /MODULE/config/optional/.yml: id: entity.node This could be done by creating a simple module that has YAML file(s) in /MODULE/config/optional. Then, create YAML configuration to “turn on” the JSON API. My example is a simple Drupal 8 site with an article content type that has a body and field_image image field, the kind of thing core provides out of the box.įirst, download and install the JSON API module. There is not much preparation needed for the source because of JSON API’s flexibility. There’s a series of short videos on YouTube that demonstrate many of the configuration options and parameters that are available in Drupal’s JSON API. (The Drupal community plans to add JSON API to Core in the future.) Because of all that flexibility, that is the solution I decided to use for my example. For example, you can sort and filter the articles, limit the fields that are returned to a subset, and bring along any or all related entities in the same query. From that one path, the consumer can select exactly what they want to retrieve just by altering the URL. You don’t need to know the path of every individual entity, just the general path for a entity type, and bundle. It puts the power in the hands of the data consumer. To further complicate things, there's an outstanding bug using GET with Views REST endpoints. And you’d have to create a View for every possible collection of data that you want to make available. You could also use Views to create a JSON endpoint, but it might be difficult to configure it to include all the required data, especially all the data from related content, like images, authors, and related nodes. You can access data from any entity by appending ?_format=json to its path, but that means you have to know the path ahead of time, and you’d be pulling in one entity at a time, which is not efficient. Why JSON API?ĭrupal 8 Core ships with two ways to export JSON data. On the target site, I used Migrate from Drupal Core 8.2.3 along with Migrate Plus and Migrate Tools. I ended up using the JSON API module, along with the REST modules in Drupal Core on the source site. Hopefully, this will save someone a lot of time in the future. Nevertheless, it took me several days to get everything working, so I thought I’d write up an article to explain how I solved the problem. ![]() Much of what I wanted to do was undocumented and confusing, but it worked well, once I figured it out. I wanted to find a way to pull data from one Drupal 8 site to another, using JSON API to expose data on one site, and Drupal’s Migrate with a JSON source on another site to consume it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |