Skip to main content
POST
/
customers
/
{customerId}
/
hedges
/
{hedgeId}
/
cancel
cURL
curl --request POST \
  --url https://api.grainfinance.co/v1/customers/{customerId}/hedges/{hedgeId}/cancel \
  --header 'Authorization: Basic <encoded-value>' \
  --header 'Content-Type: application/json' \
  --header 'X-Customer-IP: <x-customer-ip>' \
  --data '
{
  "reason": "Transaction cancelled by customer"
}
'
import requests

url = "https://api.grainfinance.co/v1/customers/{customerId}/hedges/{hedgeId}/cancel"

payload = { "reason": "Transaction cancelled by customer" }
headers = {
"X-Customer-IP": "<x-customer-ip>",
"Authorization": "Basic <encoded-value>",
"Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'POST',
headers: {
'X-Customer-IP': '<x-customer-ip>',
Authorization: 'Basic <encoded-value>',
'Content-Type': 'application/json'
},
body: JSON.stringify({reason: 'Transaction cancelled by customer'})
};

fetch('https://api.grainfinance.co/v1/customers/{customerId}/hedges/{hedgeId}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.grainfinance.co/v1/customers/{customerId}/hedges/{hedgeId}/cancel",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'reason' => 'Transaction cancelled by customer'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Basic <encoded-value>",
"Content-Type: application/json",
"X-Customer-IP: <x-customer-ip>"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.grainfinance.co/v1/customers/{customerId}/hedges/{hedgeId}/cancel"

payload := strings.NewReader("{\n \"reason\": \"Transaction cancelled by customer\"\n}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("X-Customer-IP", "<x-customer-ip>")
req.Header.Add("Authorization", "Basic <encoded-value>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.post("https://api.grainfinance.co/v1/customers/{customerId}/hedges/{hedgeId}/cancel")
.header("X-Customer-IP", "<x-customer-ip>")
.header("Authorization", "Basic <encoded-value>")
.header("Content-Type", "application/json")
.body("{\n \"reason\": \"Transaction cancelled by customer\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.grainfinance.co/v1/customers/{customerId}/hedges/{hedgeId}/cancel")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-Customer-IP"] = '<x-customer-ip>'
request["Authorization"] = 'Basic <encoded-value>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"reason\": \"Transaction cancelled by customer\"\n}"

response = http.request(request)
puts response.read_body
{
  "id": "1b0ada1e-fa1b-4cfe-a553-01b340c5650e",
  "transactionId": "4d78ac65-2c3f-47e2-8bf3-3f76124e9d27"
}
{
"message": "Can't perform this action",
"reason": "Supplied object is in *Cancelled* state, which prevents performing this action"
}
{
"message": "Can't perform this action",
"reason": "Supplied object is in *Cancelled* state, which prevents performing this action"
}
{
"message": "Can't perform this action",
"reason": "Supplied object is in *Cancelled* state, which prevents performing this action"
}
{
"message": "Can't perform this action",
"reason": "Supplied object is in *Cancelled* state, which prevents performing this action"
}
{
"message": "Could not parse IP address (v4 or v6) for ip"
}

Authorizations

Authorization
string
header
required

Basic authentication using the partner API keys from https://console.grainfinance.co/keys

Headers

X-Customer-IP
string<IPv4>
required

The IPv4 address of the browser from which the customer contacts your platform.
example: 192.158.1.38

Pattern: ((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)\.?\b){4}

Path Parameters

customerId
string
required

The id of the customer within the Grain platform.

hedgeId
string
required

The id of the hedge within the Grain platform.

Body

application/json
reason
string

Description of the reason the hedge was canceled.

Example:

"Transaction cancelled by customer"

Response

Hedge Cancelled

The response of a hedge action. Includes the reference to the relevant objects.

id
string<uuid>
required

The id of the created object.

Pattern: [0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}
Example:

"1b0ada1e-fa1b-4cfe-a553-01b340c5650e"

transactionId
string<uuid>

The id of the transaction within the Grain platform.

Pattern: [0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-4[0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}
Example:

"4d78ac65-2c3f-47e2-8bf3-3f76124e9d27"