CSV Import
Category: Data & Analytics
This page is generated from the Air Pipe marketplace. Browse it live to install into your organization.
Overview
Accept a posted CSV body, parse it into rows, and bulk-insert them into a Postgres contacts table. Demonstrates parse_csv over the raw request body plus a lookup fan-out insert.
Endpoints
- POST
contacts/import— parse a posted CSV and bulk-insert rows
Required variables
ap_var::DATABASE_URL— Postgres connection string
Configuration
csv_import.yml
name: CsvImport
description: >
Accept a posted CSV body, parse it into rows, and bulk-insert them into a
Postgres contacts table. Demonstrates parse_csv over the raw request body plus
a lookup fan-out insert.
docs: true
# Required managed variables:
# DATABASE_URL — Postgres connection string
global:
databases:
main:
driver: postgres
conn_string: "a|ap_var::DATABASE_URL|"
interfaces:
contacts/import:
output: http
method: POST
summary: Parse a posted CSV and bulk-insert the rows
actions:
- name: ParseCsv
input: a|raw_body|
post_transforms:
- parse_csv: "$"
- name: InsertRows
run_when_succeeded: [ParseCsv]
lookup: a|ParseCsv|
actions:
- name: InsertOne
database: main
query: |-
INSERT INTO contacts (name, email)
VALUES (a|body::name->single_quote|, a|body::email->single_quote|)
ON CONFLICT (email) DO NOTHING
- name: Respond
run_when_succeeded: [InsertRows]
json_output: |-
{ "status": "imported" }