Search.../

getTransaction( )

Developer Preview

Retrieves a transaction using the transaction ID.

Description

The getTransaction() function returns a Promise that resolves to a loyalty transaction.

A loyalty transaction includes any activity that changes a loyalty account point balance, such as adjusting, earning, or redeeming loyalty points. If you want to retrieve many, or all, of the transactions for a specific loyalty account, use the listTransactions() function.

Note: Only visitors with Manage Loyalty permissions can retrieve a loyalty transaction.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function getTransaction(_id: string): Promise<GetTransactionResponse>

getTransaction Parameters

NAME
TYPE
DESCRIPTION
_id
string

Transaction ID.

Returns

Return Type:

Promise<
GetTransactionResponse
>
NAME
TYPE
DESCRIPTION
transaction
Transaction

Retrieved transaction.

Was this helpful?

Get a transaction

Copy Code
1import { accounts } from 'wix-loyalty.v2';
2
3// Sample transactionId value: '262c8eb0-123e-4117-9fe6-4973a3551688'
4
5export async function myGetTransactionFunction() {
6 try {
7 const retrievedTransaction = await accounts.getTransaction(transactionId);
8
9 const transactionType = retrievedTransaction.transaction.type;
10 const transactionDate = retrievedTransaction.transaction._createdDate;
11
12 console.log('Success! That transaction was created on ', transactionDate, ' and is a ', transactionType, ' type.');
13 return retrievedTransaction;
14 } catch (error) {
15 console.error(error);
16 }
17}
18
19/* Promise resolves to:
20 * {"transaction": {
21 * "_id": "262c8eb0-123e-4117-9fe6-4973a3551688",
22 * "amount": 5,
23 * "type": "ADJUST",
24 * "description": "",
25 * "_createdDate": "2021-12-07T07:30:23.749Z",
26 * "rewardId": null,
27 * "appId": "553c79f3-5625-4f38-b14b-ef7c0d1e87df",
28 * "idempotencyKey": null
29 * }}
30