AkahuClient

Struct AkahuClient 

Source
pub struct AkahuClient { /* private fields */ }
Expand description

The main Akahu API client.

Use the builder pattern to construct a new client.

Implementations§

Source§

impl AkahuClient

Source

pub async fn get_accounts( &self, user_token: &UserToken, ) -> Result<ListResponse<Account>, AkahuError>

Get a list of all accounts that the user has connected to your application.

§Arguments
  • user_token - The user’s access token obtained through OAuth
§Returns

A response containing all accounts the user has connected to your application. The returned account data depends on the permissions your application has been granted. Access the accounts via the .items field.

[https://developers.akahu.nz/reference/get_accounts]

Source

pub async fn get_account( &self, user_token: &UserToken, account_id: &AccountId, ) -> Result<ItemResponse<Account>, AkahuError>

Get a specific account by its ID.

§Arguments
  • user_token - The user’s access token obtained through OAuth
  • account_id - The unique identifier for the account (prefixed with acc_)
§Returns

A response containing the account details for the specified account. The returned account data depends on the permissions your application has been granted. Access the account via the .item field.

[https://developers.akahu.nz/reference/get_accounts-id]

Source

pub async fn revoke_account_access( &self, user_token: &UserToken, account_id: &AccountId, ) -> Result<(), AkahuError>

👎Deprecated: This endpoint is deprecated for accounts with official open banking connections. Use the Revoke Access To Authorisation endpoint instead.

Revoke your application’s access to a specific account.

Note: This endpoint is deprecated for accounts with official open banking connections. Accounts connected via official open banking cannot be revoked on an individual basis. Instead, you must either:

  • Direct users through the OAuth flow to adjust permissions with their bank
  • Use the Revoke Access To Authorisation endpoint to revoke the entire authorization
§Arguments
  • user_token - The user’s access token obtained through OAuth
  • account_id - The unique identifier for the account to revoke access from
§Returns

Returns Ok(()) on successful revocation. Returns an error (400) when attempting to revoke accounts with connection_type of “official”.

[https://developers.akahu.nz/reference/delete_accounts-id]

Source§

impl AkahuClient

Source

pub async fn get_me(&self, user_token: &UserToken) -> Result<User, AkahuError>

Get the authenticated user’s profile information.

This endpoint retrieves information about the user who authorized your application, including their unique identifier and basic profile data. The visibility of certain fields depends on the permissions granted to your application.

§Arguments
  • user_token - The user’s access token obtained through OAuth
§Returns

The user’s profile information, including:

  • User ID
  • Account creation timestamp
  • First name (if available)
  • Last name (if available)
  • Email address (requires AKAHU scope)
  • Access granted timestamp (when the user authorized your app)
§Scopes

This endpoint requires user-scoped authentication. The AKAHU scope is needed to access the user’s email address and other profile information.

[https://developers.akahu.nz/reference/get_me]

Source§

impl AkahuClient

Source

pub async fn refresh_all_accounts( &self, user_token: &UserToken, ) -> Result<(), AkahuError>

Refresh all accounts connected to your application.

This endpoint initiates an on-demand data refresh across all accounts. Account data such as balance and transactions are periodically refreshed by Akahu and enriched asynchronously, providing clean and consistent data across financial institutions.

Note: Data enrichment occurs asynchronously after the refresh request.

§Arguments
  • user_token - The user’s access token obtained through OAuth
§Returns

Returns Ok(()) on successful refresh initiation.

[https://developers.akahu.nz/reference/post_refresh]

Source

pub async fn refresh_account_or_connection<Id: AsRef<str>>( &self, user_token: &UserToken, id: Id, ) -> Result<(), AkahuError>

Refresh a specific account or connection.

This endpoint initiates a data refresh for either a specific financial institution connection or individual account.

ID Type Behavior:

  • Connection ID: Triggers a refresh for all accounts held at that financial institution
  • Account ID: Refreshes that specific account plus any other accounts sharing the same login credentials. For example, if the user has three ASB accounts from a single set of login credentials and you request a refresh for one, the other two accounts will also be refreshed.

Note: Data enrichment occurs asynchronously after the refresh request.

§Arguments
  • user_token - The user’s access token obtained through OAuth
  • id - Either a Connection ID or Account ID
§Returns

Returns Ok(()) on successful refresh initiation.

[https://developers.akahu.nz/reference/post_refresh-id]

Source§

impl AkahuClient

Source

pub async fn get_transactions( &self, user_token: &UserToken, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, cursor: Option<Cursor>, ) -> Result<PaginatedResponse<Transaction>, AkahuError>

Get a list of the user’s settled transactions within a specified time range.

This endpoint returns settled transactions for all accounts that the user has connected to your application. The response is paginated - use the cursor.next value to fetch subsequent pages.

Important Notes:

  • Time range defaults to the entire range accessible to your app if not specified
  • Transactions will look different depending on your app’s permissions
  • All transaction timestamps are in UTC
  • The start query parameter is exclusive (transactions after this timestamp)
  • The end query parameter is inclusive (transactions through this timestamp)
  • All Akahu timestamps use millisecond resolution (e.g. 2025-01-01T11:59:59.999Z)
  • Each page contains a maximum of 100 transactions
  • When querying multiple pages, use the same start/end parameters with the cursor
§Arguments
  • user_token - The user’s access token obtained through OAuth
  • query - Optional query parameters to filter by date range and paginate
§Returns

A paginated response containing transactions and a cursor for fetching more pages.

[https://developers.akahu.nz/reference/get_transactions]

Source

pub async fn get_pending_transactions( &self, user_token: &UserToken, ) -> Result<Vec<PendingTransaction>, AkahuError>

Get a list of the user’s pending transactions.

This endpoint returns pending transactions for all accounts that the user has connected to your application. Pending transactions are not stable - the date or description may change due to the unreliable nature of underlying NZ bank data. They are not assigned unique identifiers and are not enriched by Akahu.

Important Notes:

  • Pending transactions may change before they settle
  • They do not have unique IDs
  • They are not enriched with merchant/category data
  • All timestamps are in UTC
  • The updated_at field indicates when the transaction was last fetched
  • This endpoint is not paginated and returns all pending transactions
§Arguments
  • user_token - The user’s access token obtained through OAuth
§Returns

A vector containing all pending transactions.

[https://developers.akahu.nz/reference/get_transactions-pending]

Source

pub async fn get_account_transactions( &self, user_token: &UserToken, account_id: &AccountId, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, cursor: Option<Cursor>, ) -> Result<PaginatedResponse<Transaction>, AkahuError>

Get settled transactions for a specific account within a specified time range.

This endpoint returns settled transactions for a specific connected account. The response is paginated - use the cursor.next value to fetch subsequent pages.

Important Notes:

  • Time range defaults to the entire range accessible to your app if not specified
  • All transaction timestamps are in UTC
  • The start query parameter is exclusive (transactions after this timestamp)
  • The end query parameter is inclusive (transactions through this timestamp)
  • All Akahu timestamps use millisecond resolution
  • Each page contains a maximum of 100 transactions
  • When querying multiple pages, use the same start/end parameters with the cursor
§Arguments
  • user_token - The user’s access token obtained through OAuth
  • account_id - The unique identifier for the account (prefixed with acc_)
  • query - Optional query parameters to filter by date range and paginate
§Returns

A paginated response containing transactions and a cursor for fetching more pages.

[https://developers.akahu.nz/reference/get_accounts-id-transactions]

Source

pub async fn get_account_pending_transactions( &self, user_token: &UserToken, account_id: &AccountId, ) -> Result<Vec<PendingTransaction>, AkahuError>

Get pending transactions for a specific account.

This endpoint returns pending transactions for a specific connected account. Pending transactions are not stable - the date or description may change due to the unreliable nature of underlying NZ bank data. They are not assigned unique identifiers and are not enriched by Akahu.

Important Notes:

  • Pending transactions may change before they settle
  • They do not have unique IDs
  • They are not enriched with merchant/category data
  • All timestamps are in UTC
  • The updated_at field indicates when the transaction was last fetched
  • This endpoint is not paginated and returns all pending transactions
§Arguments
  • user_token - The user’s access token obtained through OAuth
  • account_id - The unique identifier for the account (prefixed with acc_)
§Returns

A vector containing all pending transactions for the account.

[https://developers.akahu.nz/reference/get_accounts-id-transactions-pending]

Source§

impl AkahuClient

Source

pub fn new<T: Into<AppToken>>( client: Client, app_id_token: T, base_url: Option<String>, ) -> Self

Create a new Akahu client.

§Arguments
  • client - The HTTP client to use for requests
  • app_id_token - Your Akahu application ID token
  • base_url - Optional custom base URL (defaults to https://api.akahu.io/v1)
Source

pub fn with_app_secret<T: Into<AppSecret>>(self, app_secret: T) -> Self

Set the app secret for app-scoped endpoints.

The app secret is required for app-scoped endpoints like Categories. These endpoints use HTTP Basic Authentication with app_id_token:app_secret.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more