CURL *curl;
CURLcode res;
// The URL to which we will send the POST request
const char *url = "https://fcsapi.com/api-v3/forex/latest";
// Create form data with parameters
const char *postfields = "id=1,2,3&access_key=API_KEY";
// Initialize libcurl
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if(curl){
// Set the URL for the POST request
curl_easy_setopt(curl, CURLOPT_URL, url);
// Specify that this is a POST request
curl_easy_setopt(curl, CURLOPT_POST, 1L);
// Set the POST fields
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfields);
// Perform the request, res will get the return code
res = curl_easy_perform(curl);
// Check for errors
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
// Always cleanup
curl_easy_cleanup(curl);
}
// Global cleanup
curl_global_cleanup();
return 0;
// Initialize the client with the base URL
var client = new RestClient("https://fcsapi.com/api-v3/forex/latest");
// Create a POST request
var request = new RestRequest(Method.POST);
// Create form data with parameters
request.AddParameter("id", "1,2,3");
request.AddParameter("access_key", "API_KEY");
// Execute the request and get the response
IRestResponse response = client.Execute(request);
// Print the response
Console.WriteLine(response.Content);
# Use curl to make a POST request to the specified URL
curl -X POST https://fcsapi.com/api-v3/forex/latest \
# Create form data with parameters
-d "id=1,2,3" \
-d "access_key=API_KEY"
package main
import (
"bytes"
"fmt"
"net/http"
"net/url"
)
func main() {
apiUrl := "https://fcsapi.com/api-v3/forex/latest"
// Create form data with parameters
data := url.Values{}
data.Set("id", "1,2,3")
data.Set("access_key", "API_KEY")
// Create a new POST request
req, err := http.NewRequest("POST", apiUrl, bytes.NewBufferString(data.Encode()))
if err != nil {
fmt.Println("Error creating request:", err)
return
}
// Set content type header
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
// Perform the request
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error making request:", err)
return
}
defer resp.Body.Close()
// Print response status
fmt.Println("Response status:", resp.Status)
}
OkHttpClient client = new OkHttpClient();
// Create form data with parameters
RequestBody requestBody = new FormBody.Builder();
.add("id", "1,2,3")
.add("access_key", "API_KEY")
.build()
// Create the request
Request request = new Request.Builder();
.url("https://fcsapi.com/api-v3/forex/latest")
.post(requestBody)
.build()
// Execute the request and get the response
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
// Print the response body
System.out.println(response.body().string());
}
// Make a POST request using Unirest
HttpResponse<String> response = Unirest.post("https://fcsapi.com/api-v3/forex/latest")
// Set the Content-Type header
.header("Content-Type", "application/x-www-form-urlencoded")
// Create form data with parameters
.field("id", "1,2,3")
.field("access_key", "API_KEY")
// Execute the request and get the response
.asString();
// Print the response body
System.out.println(response.getBody());
// Create an instance of AsyncHttpClient
AsyncHttpClient asyncHttpClient = Dsl.asyncHttpClient();
// Build the POST request
Request Request = Dsl.post("https://fcsapi.com/api-v3/forex/latest");
// Create form data with parameters
.addFormParam("id", "1,2,3")
.addFormParam("access_key", "API_KEY")
.build();
// Execute the request asynchronously
asyncHttpClient.executeRequest(request)
.toCompletableFuture();
.thenAccept(response -> {
// Print the response status code
System.out.println("Response status code: " + response.getStatusCode());
// Print the response body
System.out.println("Response body: " + response.getResponseBody());
})
.join();
// Close the AsyncHttpClient instance
asyncHttpClient.close();
// Create form data with parameters
const formData = new FormData();
formData.append("id", "1,2,3");
formData.append("access_key", "API_KEY");
// Send a POST request to the API
fetch("https://fcsapi.com/api-v3/forex/latest", {
method: "POST",
headers: {
// Set content type to form-urlencoded
"Content-Type": "application/x-www-form-urlencoded"
},
body: formData
})
// Parse the JSON response
.then(response => response.json())
// Log the data to the console
.then(data => console.log(data))
// Log any errors to the console
.catch(error => console.error("Error:", error))
Real-time rates: Find below a simple jQuery.ajax example of getting exchange rate data via the FCS API's latest endpoint.
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script>
access_key = "API_KEY"; // Your API access key, Signup to get API KEY
id = '1,2,3,4'; // Forex ids
$.ajax({
url: "https://fcsapi.com/api-v3/forex/latest?id=" + id + "&access_key=" + access_key,
type: "GET", // GET or POST
dataType: "json",
success: function(data) {
console.log("Price of "+data.response[0].symbol + " is "+data.response[0].price);// Price of EUR/USD is 1.1064;
}
});
</script>
// Create form data with parameters
var formData = new FormData();
formData.append("id", "1,2,3");
formData.append("access_key", "API_KEY");
// Create a new XMLHttpRequest object
var xhr = new XMLHttpRequest();
// Configure the request
xhr.open("POST", "https://fcsapi.com/api-v3/forex/latest", true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Set up a function to handle the response
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && xhr.status == 200) {
// Request was successful, handle the response here
console.log(xhr.responseText);
}
};
// Send the request with the parameters
xhr.send(formData);
// Require the 'request' library
const request = require('request');
// Define the request options
const options = {
url: "https://fcsapi.com/api-v3/forex/latest",
method: "POST",
// Create form data with parameters
form: {
id: '1,2,3',
access_key: 'API_KEY',
}
};
// Make the HTTP request
request(options, function (error, response, body) {
if (error) {
console.error('Error:', error);
}
else {
console.log('Response:', body);
}
});
// Require the 'unirest' library
const unirest = require('unirest');
// Make a POST request to the specified URL
unirest.post("https://fcsapi.com/api-v3/forex/latest")
.headers({'Content-Type': 'application/json'})
// Create form data with parameters
.field('id', "1,2,3")
.field('access_key', "API_KEY")
.end(function (response) {
console.log(response.body);
});
// Require the 'axios' library
const axios = require('axios');
// Create form data with parameters
const data = {
id: '1,2,3',
access_key: 'API_KEY'
};
// Making a POST request using Axios
axios.post("https://fcsapi.com/api-v3/forex/latest", data)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error("error", error);
});
$access_key = "API_KEY"; // Your API access key, Signup to get API KEY
$symbol = "EUR/USD"; // FX Pairs
// Enter your API URL below
$api_url = "https://fcsapi.com/api-v3/forex/latest";
$post = "symbol=".$symbol."&access_key=".$access_key;
// Initialize CURL:
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$json = curl_exec($ch); // Store the data
curl_close($ch);
$response = json_decode($json, true); // convert JSON into Array
foreach ($response['response'] as $key => $value) {
echo "<br>Open Price Of ".$value['symbol']." is ".$value['price']; // Open Price Of EUR/USD is 1.1266
}
// Create form data with parameters
$data = array(
'id' => '1,2,3',
'access_key' => 'API_KEY',
);
Set POST data
$data_query = http_build_query($data);
// Initialize a new HTTP request
$request = new HttpRequest("https://fcsapi.com/api-v3/forex/latest", HttpRequest::METH_POST);
$request->addHeaders(array(
'Content-Type' => 'application/x-www-form-urlencoded',
});
$request->setBody($data_query);
// Send the request and capture the response
try {
$response = $request->send();
// Display the response
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
import requests
# Create form data with parameters
params = {
"id": "1,2,3",
"access_key": "API_KEY"
}
# Make the POST request
response = requests.post("https://fcsapi.com/api-v3/forex/latest", data=params)
# Print the response
print(response.text)
require 'uri'
require 'net/http'
url = URI("https://fcsapi.com/api-v3/forex/latest")
# Create form data with parameters
params = {
"id": "1,2,3",
"access_key": "API_KEY"
}
# Create the HTTP object
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
# Create the request
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/x-www-form-urlencoded"
request.set_form_data(params)
# Send the request
response = http.request(request)
# Output the response
puts "Response code: #{response.code}"
puts "Response body: #{response.body}"
http --ignore-stdin --form --follow --timeout 3600 POST 'https://fcsapi.com/api-v3/forex/latest' \
# Create form data with parameters
"id"="1,2,3" \
"access_key"="API_KEY"
wget --quiet \
--method=POST \
--header='Content-Type: application/x-www-form-urlencoded' \
--body-data='id=1,2,3&access_key=API_KEY' \
--output-document=- \
https://fcsapi.com/api-v3/forex/latest
There are multiple errors that help you to understand issue with your API response.
Code | Details |
---|---|
200 | Your API is working. Response successfully |
101 | API Key error : Your access key is wrong, Please login in your dashboard and get your API KEY. |
102 | Your Account is not activated. |
103 | Your Account is blocked. |
104 | API Key error : You have not set your access_key in parameters. |
111 | Full access is not allow with DEMO API key, so please signup and get your api key to unlock full access on FCS. |
112 | Data not found, it may be you set wrong values and it may be no data from our side. More error details will be send in API response. |
113 | Required parameters are missing, Please check api documentaion also check message in API response for more error details. |
211 | You have used your all monthly API request limit. |
212 | Your Account is expired, You need to pay your montly fee or downgrade to free version. |
213 | Error 213 is only for Free user, free user are not allow more than 1 request per minute.. |