> For the complete documentation index, see [llms.txt](https://ipforensics.gitbook.io/ipforensics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ipforensics.gitbook.io/ipforensics/api/exchange-rate-api/currency-swap-endpoint.md).

# Currency Swap Endpoint

Our Currency Swap API endpoint is useful for applications where you just want to convert between two specific currencies and aren't interested in any others.

You'll need to choose your base currency code and the target currency you'd like to get the exchange rate for.&#x20;

You'll then get a minimal JSON response back from our API with exactly the data you need. It's a much smaller response than the one you'd get from our Live Rate endpoint - quick & easy to develop with.

{% hint style="success" %}
Each request to the currency swap endpoint consumes 1 token.
{% endhint %}

### Code Snippet

{% tabs %}
{% tab title="PHP Curl" %}

```javascript
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://ipforensics.net/api/v1/currency/swap?apikey=IPF-36ae36a6-4a32-4fae-a422-e45e70b0a515-X&to=NGN&from=USD',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

```

{% endtab %}

{% tab title="Javascript" %}

```javascript
var requestOptions = {
  method: 'POST',
  redirect: 'follow'
};

fetch("https://ipforensics.net/api/v1/currency/swap?apikey=IPF-36ae36a6-4a32-4fae-a422-e45e70b0a515-X&to=NGN&from=US", requestOptions)
  .then(response => response.text())
  .then(result => console.log(result))
  .catch(error => console.log('error', error));
```

{% endtab %}

{% tab title="Node Js" %}

```javascript
var axios = require('axios');

var config = {
  method: 'post',
  url: 'https://ipforensics.net/api/v1/currency/swap?apikey=IPF-36ae36a6-4a32-4fae-a422-e45e70b0a515-X&to=NGN&from=US',
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://ipforensics.net/api/v1/currency/swap?apikey=IPF-36ae36a6-4a32-4fae-a422-e45e70b0a515-X&to=NGN&from=US"

payload={}

response = requests.request("POST", url, data=payload)

print(response.text)

```

{% endtab %}

{% tab title="C#" %}

```csharp
var client = new RestClient("https://ipforensics.net/api/v1/currency/swap?apikey=IPF-36ae36a6-4a32-4fae-a422-e45e70b0a515-X&to=NGN&from=US");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
```

{% endtab %}
{% endtabs %}

### Sample Response

```javascript
{
    "status": true,
    "code": 200,
    "message": "Successful",
    "meta_data": {
        "from": "usd",
        "to": "ngn",
        "exchange_rate": 440.28684
    }
}
```

### Endpoint

## Returns the swap currency.

<mark style="color:blue;">`GET`</mark> `https://ipforensics.net/api/v1/currency/swap?apikey=...&to=NGN&from=USD`

Returns response object and a metadata of the request

#### Query Parameters

| Name                                     | Type   | Description                        |
| ---------------------------------------- | ------ | ---------------------------------- |
| apikey<mark style="color:red;">\*</mark> | String | Your API key                       |
| from<mark style="color:red;">\*</mark>   | String | Specify the currency to swap from. |
| to<mark style="color:red;">\*</mark>     | String | Specify the currency to swap to.   |

{% tabs %}
{% tab title="200: OK " %}

```javascript
{
    "status": true,
    "code": 200,
    "message": "Successful",
    "meta_data": {
        "from": "usd",
        "to": "ngn",
        "exchange_rate": 440.28684
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://ipforensics.gitbook.io/ipforensics/api/exchange-rate-api/currency-swap-endpoint.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
