> For the complete documentation index, see [llms.txt](https://docs.switchappgo.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.switchappgo.com/payments/transactions/initialize-a-transaction.md).

# Initialize a transaction

{% hint style="info" %}
**NOTE:** This section describes how to initialize a transaction on the server-side ie within your own application server using secret keys. To initialize a transaction on the client side (ie using public API keys), check out the [quickstart section](/quick-start.md).
{% endhint %}

This API endpoint initializes a new payment from your backend/server.

A currency, amount, and customer object (with at least the customer's email) must be supplied. The customer is added to your list of customers if they do not already exist.

You may also provide a **`tx_ref`** (transaction reference) for the payment transaction. This must be a unique alpha-numeric string that cannot be repeated again in your transaction list (for at least 2 years). If you do not know how to generate this, we've got you. Leave it blank and we will fill it in.

{% hint style="info" %}
**NOTE:** Initializing a transaction only indicates you want a customer to make a payment. However, the customer may cancel without completing the payment or payment may simply fail. So always make sure you [**verify**](/payments/transactions/verify-transaction.md) the transaction status before giving value.
{% endhint %}

{% openapi src="/files/D2OnIDDY2fzSVTk2AYNl" path="/v1/transactions/server-initialize" method="post" %}
[merchant-api-swagger-10-04-2023.json](https://163660187-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8qcR8TOKMHOvHEJFAJcO%2Fuploads%2Fz1Hkjfk2wl3pDM0TQvng%2Fmerchant-api-swagger-10-04-2023.json?alt=media\&token=79cc08f6-9596-401d-993c-32a29da7d56f)
{% endopenapi %}

{% tabs %}
{% tab title="curl" %}

```clike
curl https://api.switchappgo.com/v1/transactions/server-initialize \
    -H "authorization: 'bearer sk_test_nTgS42KNdKr6Ts798DT'" \
    -d amount='3000' \
    -d currency='USD' \
    -d customer='{"email":"customer@email.com"}'
```

{% endtab %}

{% tab title="node" %}

```javascript
const switchapp = require('switchapp')('sk_test_nTgS42KNdKr6Ts798DT');

const newTx = await switchapp.transactions.serverInitialize({
    amount: 3000,
    currency: 'USD',
    customer: { email:'customer@email.com' },
})
```

{% endtab %}
{% endtabs %}
