Purchase a policy
curl --request POST \
--url https://app.microcrop.app/api/policies/purchase \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"farmerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productType": "CROP",
"plotId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"herdId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"sumInsured": 1001,
"durationDays": 197
}
'import requests
url = "https://app.microcrop.app/api/policies/purchase"
payload = {
"farmerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productType": "CROP",
"plotId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"herdId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"sumInsured": 1001,
"durationDays": 197
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
farmerId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
productType: 'CROP',
plotId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
herdId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
sumInsured: 1001,
durationDays: 197
})
};
fetch('https://app.microcrop.app/api/policies/purchase', 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://app.microcrop.app/api/policies/purchase",
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([
'farmerId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'productType' => 'CROP',
'plotId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'herdId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'sumInsured' => 1001,
'durationDays' => 197
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$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://app.microcrop.app/api/policies/purchase"
payload := strings.NewReader("{\n \"farmerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productType\": \"CROP\",\n \"plotId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"herdId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"sumInsured\": 1001,\n \"durationDays\": 197\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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://app.microcrop.app/api/policies/purchase")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"farmerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productType\": \"CROP\",\n \"plotId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"herdId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"sumInsured\": 1001,\n \"durationDays\": 197\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.microcrop.app/api/policies/purchase")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"farmerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productType\": \"CROP\",\n \"plotId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"herdId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"sumInsured\": 1001,\n \"durationDays\": 197\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"policy": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"policyNumber": "<string>",
"status": "PENDING",
"premiumPaid": true,
"sumInsured": 123,
"premium": 123,
"coverageType": "<string>",
"onChainPolicyId": "<string>",
"daysRemaining": 123,
"payouts": [
{}
],
"damageAssessments": [
{}
]
},
"paymentInstructions": {
"amount": 123,
"policyNumber": "<string>",
"message": "<string>"
}
}
}{
"success": false,
"error": {
"code": "INVALID_INPUT",
"message": "<string>",
"details": "<unknown>"
}
}{
"success": false,
"error": {
"code": "INVALID_INPUT",
"message": "<string>",
"details": "<unknown>"
}
}Policies
Purchase a policy
Creates a PENDING policy awaiting premium. Requires the organization to be KYB-verified and the farmer’s KYC to be APPROVED.
POST
/
policies
/
purchase
Purchase a policy
curl --request POST \
--url https://app.microcrop.app/api/policies/purchase \
--header 'Content-Type: application/json' \
--header 'x-api-key: <api-key>' \
--data '
{
"farmerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productType": "CROP",
"plotId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"herdId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"sumInsured": 1001,
"durationDays": 197
}
'import requests
url = "https://app.microcrop.app/api/policies/purchase"
payload = {
"farmerId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"productType": "CROP",
"plotId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"herdId": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"sumInsured": 1001,
"durationDays": 197
}
headers = {
"x-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'x-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({
farmerId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
productType: 'CROP',
plotId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
herdId: '3c90c3cc-0d44-4b50-8888-8dd25736052a',
sumInsured: 1001,
durationDays: 197
})
};
fetch('https://app.microcrop.app/api/policies/purchase', 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://app.microcrop.app/api/policies/purchase",
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([
'farmerId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'productType' => 'CROP',
'plotId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'herdId' => '3c90c3cc-0d44-4b50-8888-8dd25736052a',
'sumInsured' => 1001,
'durationDays' => 197
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"x-api-key: <api-key>"
],
]);
$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://app.microcrop.app/api/policies/purchase"
payload := strings.NewReader("{\n \"farmerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productType\": \"CROP\",\n \"plotId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"herdId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"sumInsured\": 1001,\n \"durationDays\": 197\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-api-key", "<api-key>")
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://app.microcrop.app/api/policies/purchase")
.header("x-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"farmerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productType\": \"CROP\",\n \"plotId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"herdId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"sumInsured\": 1001,\n \"durationDays\": 197\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://app.microcrop.app/api/policies/purchase")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"farmerId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"productType\": \"CROP\",\n \"plotId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"herdId\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\",\n \"sumInsured\": 1001,\n \"durationDays\": 197\n}"
response = http.request(request)
puts response.read_body{
"success": true,
"data": {
"policy": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"policyNumber": "<string>",
"status": "PENDING",
"premiumPaid": true,
"sumInsured": 123,
"premium": 123,
"coverageType": "<string>",
"onChainPolicyId": "<string>",
"daysRemaining": 123,
"payouts": [
{}
],
"damageAssessments": [
{}
]
},
"paymentInstructions": {
"amount": 123,
"policyNumber": "<string>",
"message": "<string>"
}
}
}{
"success": false,
"error": {
"code": "INVALID_INPUT",
"message": "<string>",
"details": "<unknown>"
}
}{
"success": false,
"error": {
"code": "INVALID_INPUT",
"message": "<string>",
"details": "<unknown>"
}
}Authorizations
Body
application/json
For CROP: plotId, sumInsured, coverageType, durationDays are required. For LIVESTOCK: herdId and season are required (sumInsured auto-calculated).
Available options:
CROP, LIVESTOCK Available options:
LRLD, SRSD Required range:
x >= 1000Available options:
DROUGHT, FLOOD, BOTH, COMPREHENSIVE, LIVESTOCK_DROUGHT, LIVESTOCK_DISEASE, LIVESTOCK_COMPREHENSIVE Required range:
30 <= x <= 365