Upload historical transactions (optional)
Your historical transactions allow Grain to evaluate your transactional risk patterns, and provide a more accurate pricing for your customers. Grain supports two methods for reporting historical transactions:
1. API - to report your transactions via the API, use the create transaction endpoint:
- cURL
- JavaScript
- Python
- Java
- C#
curl --request POST \
--url https://api.grainfinance.co/v1/customers/{customerId}/transactions \
--header "Content-Type: application/json" \
--header 'Authorization: Basic CLIENT_ID:CLIENT_SECRET' \
--data '{
"fromCurrency": "{fromCurrency}",
"toCurrency": "{toCurrency}",
"toCurrencyAmount": "{toCurrencyAmount}",
"issuedAt": "{issuedAt}",
"dueAt": "{dueAt}"
}'
const url = 'https://api.grainfinance.co/v1/customers/{customerId}/transactions';
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Basic CLIENT_ID:CLIENT_SECRET'
},
body: JSON.stringify({
"fromCurrency": "{fromCurrency}",
"toCurrency": "{toCurrency}",
"toCurrencyAmount": "{toCurrencyAmount}",
"issuedAt": "{issuedAt}",
"dueAt": "{dueAt}"
})
};
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
import requests
url = 'https://api.grainfinance.co/v1/customers/{customerId}/transactions'
payload = {
"fromCurrency": "{fromCurrency}",
"toCurrency": "{toCurrency}",
"toCurrencyAmount": "{toCurrencyAmount}",
"issuedAt": "{issuedAt}",
"dueAt": "{dueAt}"
}
headers = {
'Content-Type': 'application/json'
}
response = requests.post(
url,
headers=headers,
json=payload
)
data = response.json()
AsyncHttpClient client = new DefaultAsyncHttpClient();
client.prepare("POST", "https://api.grainfinance.co/v1/customers/{customerId}/transactions")
.setHeader("Content-Type", "application/json")
.setHeader("Authorization", "Basic CLIENT_ID:CLIENT_SECRET")
.setBody("{
"fromCurrency": "{fromCurrency}",
"toCurrency": "{toCurrency}",
"toCurrencyAmount": "{toCurrencyAmount}",
"issuedAt": "{issuedAt}",
"dueAt": "{dueAt}"
}")
.execute()
.toCompletableFuture()
.thenAccept(System.out::println)
.join();
client.close();
using RestSharp;
var options = new RestClientOptions("https://api.grainfinance.co/v1/customers/{customerId}/transactions");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Basic CLIENT_ID:CLIENT_SECRET");request.AddParameter("data", "{
"fromCurrency": "{fromCurrency}",
"toCurrency": "{toCurrency}",
"toCurrencyAmount": "{toCurrencyAmount}",
"issuedAt": "{issuedAt}",
"dueAt": "{dueAt}"
}");
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content);
This will create a business transaction on the Grain platform and return its ID:
{
"id": "{transactionId}"
}
To update the status of previously reported transactions, you can use the transaction canceled and transaction paid endpoints respectively.
2. File sharing - Contact Grain via support@grainfinance.co to share with us the transactions file manually.