Skip to content

Record Import Step

pre_upsert_records takes a list of records, usually the body of an http_get, and creates or updates one Promptless CPT Pages record for each. It needs Promptless CPT Pages 0.9.0 or later (0.10.0 or later for featured_image_url); without it the step fails with dependency_missing. The full workflow around it is in Importing records.

SettingRequiredWhat it doesDefault
post_typeYesThe record type’s slug, registered in Promptless CPT Pages.—
sourceYesA short, permanent key for the system the records come from, such as recdesk.—
recordsYesThe list, usually "{{ steps.fetch.body.items }}". An object of records is treated as a list.—
mapYesHow each record becomes a CPT Pages record; see below.—
expect_min_recordsNoFail if fewer records arrive.1
max_failure_ratioNoFail if more than this share of records cannot be written, from 0 to 1.0.1
missing_upstreamNokeep or draft: what to do with records of this source the list no longer contains.keep

The map is filled in once per record, with the current record available as {{ item.<field> }}. Other paths (vars, steps, now()) work too.

KeyRequiredWhat it sets
external_idYesThe record’s id in the other system. With post_type and source, it is the record’s identity.
titleYesThe title.
content, excerptNoThe body and the excerpt.
statusNoThe WordPress status, such as publish or draft. A new record without one is published; an existing one keeps its status.
fieldsNoAn object of CPT Pages field keys and values.
taxonomiesNoAn object of taxonomy slugs and terms: a list, or text separated by commas.
featured_image_idNoA Media Library attachment id.
featured_image_urlNoAn image address. It is downloaded once per address and reused on later runs.
"map": {
"external_id": "{{ item.id }}",
"title": "{{ item.name }}",
"fields": { "event_start": "{{ item.startDate }}", "location": "{{ item.facility.name }}" },
"taxonomies": { "program_category": "{{ item.category }}" }
}
ResultWhen
CreatedNo record of this type has this source and external_id.
UpdatedOne exists and the mapped values changed. Only the keys in the map are written.
UnchangedOne exists and nothing in the mapped values changed. Nothing is written.
Failedexternal_id or title came out empty, or CPT Pages refused the record. Listed in failed; the other records carry on.

After every record, the step checks its guards:

  • fewer than expect_min_records records arrived: the step fails with upstream_shape before writing anything;
  • more than max_failure_ratio of them failed: the step fails with upstream_shape; the records already written stay.

Only when both guards pass and missing_upstream is draft are published records of this source that were not in the list switched to draft. Records are never deleted.

FieldWhat it holds
received_countRecords in the list.
created_count, updated_count, unchanged_count, failed_count, drafted_countCounts by result.
created_ids, updated_ids, unchanged_ids, drafted_idsThe post ids.
failedEach failure’s index, external_id and error.
warningsMap paths missing on some records (with counts), and taxonomy or image problems.

The run history records the map as written, not filled in.

Available since FlowMint Workflows 0.8.0.