WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

A basic migration from a JSON url feed

Submitted by barnettech on Thu, 07/20/2023 - 16:35

Source grabs it from the JSON feed, process does the mapping to the Drupal fields in the publication2 content type, and destination defines the content type it will map into:

id: publication_from_westernstubservices
label: 'UD host node migration for remote JSON source example'
migration_tags:
  - WS JSON Source
source:
  constants:
    TITLE_SUFFIX: ' (Imported from remote file)'

  plugin: url
  data_fetcher_plugin: http
  data_parser_plugin: json

  urls:
    - https://data.fs.usda.gov/research/westernstubservices/productsservices?station_id=PNW&unit_id=&days_changed=-1&station_mode_id=3&format=json
    #- modules/custom/ud_migrations/ud_migrations_json_source/sources/udm_remote.json

  # XPath-like selector. The slash (/) at the beginning is optional.
  item_selector: /response/products_services
  fields:
    - name: src_product_id
      label: 'Product ID'
      selector: product_id
    - name: src_title
      label: 'Title'
      selector: title
  ids:
    src_product_id:
      type: integer
process:
  title: src_title
  field_product_id2: src_product_id
destination:
  plugin: 'entity:node'
  default_bundle: publication2
  optional: []