Skip to content

Configuration

Vic Shóstak edited this page Jun 18, 2023 · 14 revisions

In this section, we'll take a closer look at how you can quickly and easily set up a configuration file to start implementing any of your tasks. You can use absolutely any format of configuration file:

  • JSON
  • YAML
  • TOML
  • HCL (Terraform)

The main condition is that your config file must contain the sections necessary for csv2api to work.

A configured config.yml file usually looks like this:

save_filtered_pk_to_csv: true

columns_order:
  - id
  - order_id
  - is_paid

csv_separator: ','

api:

  base_url: my-api-server.com
  base_url_schema: https
  auth_method: Bearer
  token: '{{ CONFIG_API_TOKEN }}'
  request_timeout: 0

  update_endpoint:
    endpoint_name: /api/v1/order/%s
    content_type: application/json
    add_pk_to_endpoint_name: true
    http_method: PATCH
    endpoint_body:
      data:
        id: id
        attributes:
          tags: tags

filter_columns:

  - column_name: order_id
    condition: NEQ
    value: ''

update_fields:

  - field_name: tags
    values:
      - paid
    conditions:
      - column_name: is_paid
        condition: EQ
        value: '1'

Let's look at each section in more detail.

save_filtered_pk_to_csv

This section accepts true or false. Allows you to specify whether to save the filtered primary keys (PK) to a CSV file.

This is useful when you need to keep track of which PK (IDs) have been filtered, to control how they change in the database or elsewhere.

columns_order

This section accepts a list of lines. Allows you to specify the order of the fields for filtering and updating.

❗️ Please note: the first element in this list is the primary key (PK), which will be used in other configuration sections.

csv_separator

This section takes the value of a string. Allows you to specify a separator between columns in a CSV data file.

The setting must match the parameters of the Go standard library package: https://pkg.go.dev/encoding/csv#Writer

Clone this wiki locally