SetuClient.Data.AA (Setu Client v1.0.0)

Copy Markdown View Source

Setu Account Aggregator FIU API client.

Flow

  1. Consentcreate_consent/2, get_consent/3, revoke_consent/2, create_multi_consent/2
  2. Data fetchcreate_data_session/2, get_data_session/2, fetch_fi_data/2
  3. Utilitiesget_last_fetch_status/2, list_data_sessions/2

Example

{:ok, consent} = SetuClient.Data.AA.create_consent(cfg, %{
  vua: "9999999999",
  fetch_type: "ONETIME",
  consent_types: ["TRANSACTIONS"],
  fi_types: ["DEPOSIT"],
  consent_duration: %{unit: "MONTH", value: 1},
  data_range: %{from: from_dt, to: to_dt}
})

# Redirect customer to consent["url"]

{:ok, session} = SetuClient.Data.AA.create_data_session(cfg, %{consent_id: consent["id"]})
{:ok, fi_data} = SetuClient.Data.AA.fetch_fi_data(cfg, session["id"])

Setu docs: https://docs.setu.co/data/account-aggregator

Summary

Functions

Creates an AA consent request.

Creates a data fetch session against an ACTIVE consent.

Merges two consent requests into a single approval flow.

Fetches FI data for a COMPLETED or PARTIAL session.

Retrieves the status of a consent request.

Retrieves the current status of a data session.

Returns the timestamp and FIP list of the most recent data fetch.

Lists all non-expired data sessions for a consent.

Revokes an active consent.

Returns a context param for account selection mode ("single" | "multi" | "multi-opt-out").

Returns a context param filtering by account type ("SAVINGS" | "CURRENT").

Returns a context param excluding specific FIP IDs (comma-separated).

Returns a context param restricting consent to specific FIP IDs (comma-separated).

Returns a context param with a custom consent purpose description.

Returns a context param filtering by transaction type ("debit" | "credit").

Functions

create_consent(cfg, params)

@spec create_consent(SetuClient.Config.t(), map()) ::
  {:ok, map()} | {:error, SetuClient.Error.t()}

Creates an AA consent request.

Redirect the customer to the url in the response.

Required

  • :vua — mobile "9999999999" or handle "9999999999@onemoney"
  • :fetch_type"ONETIME" or "PERIODIC"
  • :consent_types — list: "PROFILE", "SUMMARY", "TRANSACTIONS"
  • :fi_types — list: "DEPOSIT", "MUTUAL_FUNDS", etc.
  • One of :consent_duration %{unit, value} or :consent_date_range %{from, to}
  • :data_range — required when "TRANSACTIONS" is in :consent_types

POST /consents

create_data_session(cfg, params)

@spec create_data_session(SetuClient.Config.t(), map()) ::
  {:ok, map()} | {:error, SetuClient.Error.t()}

Creates a data fetch session against an ACTIVE consent.

Poll get_data_session/2 or wait for SESSION_STATUS_UPDATE webhook.

Required

  • :consent_id

POST /v2/sessions

create_multi_consent(cfg, params)

@spec create_multi_consent(SetuClient.Config.t(), map()) ::
  {:ok, map()} | {:error, SetuClient.Error.t()}

Merges two consent requests into a single approval flow.

POST /v2/consents/collection

fetch_fi_data(cfg, session_id)

@spec fetch_fi_data(SetuClient.Config.t(), String.t()) ::
  {:ok, map()} | {:error, SetuClient.Error.t()}

Fetches FI data for a COMPLETED or PARTIAL session.

GET /v2/sessions/:id/fetch

get_consent(cfg, consent_id, expanded \\ false)

@spec get_consent(SetuClient.Config.t(), String.t(), boolean()) ::
  {:ok, map()} | {:error, SetuClient.Error.t()}

Retrieves the status of a consent request.

Pass expanded: true for the full consent configuration.

GET /consents/:id[?expanded=true]

get_data_session(cfg, session_id)

@spec get_data_session(SetuClient.Config.t(), String.t()) ::
  {:ok, map()} | {:error, SetuClient.Error.t()}

Retrieves the current status of a data session.

GET /v2/sessions/:id

get_last_fetch_status(cfg, consent_id)

@spec get_last_fetch_status(SetuClient.Config.t(), String.t()) ::
  {:ok, map()} | {:error, SetuClient.Error.t()}

Returns the timestamp and FIP list of the most recent data fetch.

GET /v2/consents/:id/fetch/status

list_data_sessions(cfg, consent_id)

@spec list_data_sessions(SetuClient.Config.t(), String.t()) ::
  {:ok, map()} | {:error, SetuClient.Error.t()}

Lists all non-expired data sessions for a consent.

GET /v2/consents/:id/data-sessions

revoke_consent(cfg, consent_id)

@spec revoke_consent(SetuClient.Config.t(), String.t()) ::
  {:ok, map()} | {:error, SetuClient.Error.t()}

Revokes an active consent.

POST /v2/consents/:id/revoke

with_account_selection_mode(mode)

@spec with_account_selection_mode(String.t()) :: map()

Returns a context param for account selection mode ("single" | "multi" | "multi-opt-out").

with_account_type(type)

@spec with_account_type(String.t()) :: map()

Returns a context param filtering by account type ("SAVINGS" | "CURRENT").

with_exclude_fips(fip_ids)

@spec with_exclude_fips(String.t()) :: map()

Returns a context param excluding specific FIP IDs (comma-separated).

with_fip_filter(fip_ids)

@spec with_fip_filter(String.t()) :: map()

Returns a context param restricting consent to specific FIP IDs (comma-separated).

with_purpose_description(desc)

@spec with_purpose_description(String.t()) :: map()

Returns a context param with a custom consent purpose description.

with_transaction_type(type)

@spec with_transaction_type(String.t()) :: map()

Returns a context param filtering by transaction type ("debit" | "credit").