# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.switchappgo.com/payments/transactions/initialize-a-transaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
