-1

I'm using JSON:API to migrate data from one Drupal 8 site to another and can successfully migrate taxonomy terms. However, the hierarchy is not preserved.

My taxonomy migration looks like this:

langcode: en
status: true
id: migration_taxonomy_tags
label: Import taxonomy
migration_group: production_import
migration_dependencies: {}
dependencies: {} 
destination:
  plugin: entity:taxonomy_term
  default_bundle: tags

source:
  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: json
  constants:
    source_base_path: 'https://sitename.com/'
  urls: https://sitename.com/jsonapi/taxonomy_term/tags?_format=api_json

  ids:
    tid:
      type: integer

  item_selector: data/

  fields:
    -
      name: tid
      label: 'Tid'
      selector: /attributes/tid
    -
      name: uuid
      label: 'Uuid'
      selector: /attributes/uuid
    -
      name: name
      label: 'Name'
      selector: /attributes/name
    -
      name: changed
      label: 'Changed'
      selector: /attributes/changed
    -
      name: status
      label: 'Status'
      selector: /attributes/status
    -
      name: description
      label: 'Description'
      selector: /attributes/description
    -
      name: path
      label: 'Path'
      selector: /attributes/path
    -
      name: parent
      label: 'Parent'
      selector: /relationships/parent

process:
  type:
    plugin: default_value
    default_value: taxonomy

  tid: tid
  uuid: uuid
  name: name
  changed: changed
  status: status
  path: path
  description: description

  parent:
    plugin: migration_lookup
    migration: migration_taxonomy_tags
    source: parent

and the endpoint returns data formatted as such:

{
  type: "taxonomy_term--geographic_location",
  id: "34f9b380-f976-4ed9-8517-916d47320cea",
  attributes: { 
    tid: 719,
    uuid: "34f9b380-f976-4ed9-8517-916d47320cea",
    langcode: "en",
    status: true,
    name: "Africa",
    description: null,
    changed: 1533567134,
    path: {
      alias: "/taxonomy/tags/africa",
      pid: 873,
      langcode: "en"
    },
  },
  relationships: {
    vid: {  
      data: {   
        type: "taxonomy_vocabulary--taxonomy_vocabulary",
        id: "e793ed10-5343-4acb-bd36-4230e5c0dfb5"
      },
      links: {
        self: "http://sitename.…320cea/relationships/vid",
        related: "http://sitename.…d9-8517-916d47320cea/vid"
      },
      parent: {
        data: {
          0: {  
            type: "taxonomy_term--geographic_location",
            id: "virtual",
            meta: { 
              links: {  
                help: { 
                  href: "https://www.drupal.org/d…pi/core-concepts#virtual",
                  meta: {…}
                }
              }
            }
          },
          links: {  
            self: "http://sitename.com/relationships/parent",
            related: "http://sitename.…8517-916d47320cea/parent""
          }
        }
      }
    }
  }
}

I've seen an answer for importing from CSV with hierarchy, but that assumes a PID field. Unfortunately, the endpoint created by JSON API doesn't return that.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.