> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ebury.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Repatriate funds in your currency

Ideal if you have clients in different geographies and are getting paid in their currencies.

Our APIs enable access to the right tools you need to repatriate all incoming funds into your home currency effortlessly.

## API endpoints call sequence

Here is an example of how the APIs can be initiated in a specific sequence to address the use case described above. Feel free to align with our Implementation team if you are looking for additional requirements and optimisations:

* Webhooks (get notified on incoming funds)
* Request for quote
* Create a trade
* Making payments

## Code snippets

## Step 1

Being subscribed to our **[Webhooks](https://postman.ebury.io/#49897e5e-56e1-471f-976a-e89e3f852f49)**  means you get notified every time you receive funds into your wallet.

```sh theme={null}
curl --location -g '{{APP_URL}}/webhooks/graphql?client_id={{client_id}}' \
--header 'X-Contact-ID: {{contact_id}}' \
--header 'Authorization: Bearer {{token}}' \
--header 'x-api-key: {{api_key}}' \
--header 'Content-Type: application/json' \
--data 'mutation createSubscription {
          createSubscription(
             input: {
               active: true
               secret: "secret"
               url: "https://httpbin.org/post"
               types: [CREDIT_INCOMING_TRANSACTION]
             }
            ){
             subscription {
               id 
             }
          }
      }
}'
```

## Step 2

Once you are ready to repatriate the funds, trigger the **[Get a quote](https://postman.ebury.io/#23fe154f-273a-49b6-85c9-0272a5d4f0bf)** endpoint in order to obtain a rate (to be used when booking your Trade) for moving funds to your home currency.

```sh theme={null}
curl --location -g '{{APP_URL}}/quotes?quote_type=quote&client_id={{client_id}}' \
--header 'Authorization: Bearer {{token}}' \
--header 'X-Contact-ID: {{contact_id}}' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {{api_key}}' \
--data '{
  "trade_type": "spot",
  "sell_currency": "GBP",
  "buy_currency": "EUR",
  "amount": 1500,
  "operation": "buy",
  "value_date": "2018-08-31"
}'
```

## Step 3

**[Book the Trade](https://postman.ebury.io/#6d1453dd-f085-4c8b-b146-dc5591e80d62)**, using the *quote \_id* you got in the previous step.

```sh theme={null}
curl --location -g '{{APP_URL}}/trades?quote_id={{quote_id}}&client_id={{client_id}}' \
--header 'X-Contact-ID: {{contact_id}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{token}}' \
--header 'x-api-key: {{api_key}}' \
--data '{
  "trade_type": "spot",
  "reason": "Any reason",
  “external_reference_id”: “your ID to track trade”
}'
```

## Step 4

Trigger the **[Initiate a payment](https://postman.ebury.io/#4a4282dc-8295-400a-a325-7b4a907365ac)** endpoint to move funds to the bank accounts you hold in your home country.

```sh theme={null}
curl --location -g '{{APP_URL}}/payments?client_id={{client_id}}' \
--header 'Authorization: Bearer {{token}}' \
--header 'X-Contact-ID: {{contact_id}}' \
--header 'x-api-key: {{api_key}}' \
--header 'Content-Type: application/json' \
--data '{
        "trade_id": "EBPOTR003771",
        "payments": [
            {
                "beneficiary_id": "EBPBEN15773",
                "account_id": "12804",
                "amount": "2",
                "email_beneficiary": "false",
                "payment_date": "2019-04-26",
                "reference": "testing"
            }
        ]
    }'
```

## Step 5

Finally **[subscribe to Webhooks](https://postman.ebury.io/#49897e5e-56e1-471f-976a-e89e3f852f49)** to get notifications when statuses change on the payment you just initiated

```sh theme={null}
curl --location -g '{{APP_URL}}/webhooks/graphql?client_id={{client_id}}' \
--header 'X-Contact-ID: {{contact_id}}' \
--header 'Authorization: Bearer {{token}}' \
--header 'x-api-key: {{api_key}}' \
--header 'Content-Type: application/json' \
--data 'mutation createSubscription {
          createSubscription(
            input: {
              active: true
              secret: "secret"
              url: "https://httpbin.org/post"
              types: [PAYMENT_STATUS_CHANGE]
            }
          ){
           subscription {
             id 
           }
       }
     }
  }'
```
