Set Cart OptIn | Climes API
This has the sample request for how to set an Opt-in status for a specific cart_id. This opted_in value can be set to true or false - depending on the users interaction with the widget. Alternatively if all orders are to be opted in, this can be directly sent via the backend.
Alternatively if all orders are to be opted in, this can be directly sent via the backend.
These API's are only for Climes Vote product.
Request Parameters
Create OptIn Schema
Name | Description | Type | Optional |
---|---|---|---|
cart_id | This is the cart_id of you store. This has to be unique and one this will be used to show the OptIn Card and Success Card for that particular order. | string | required |
opted_id | This is the value that denotes if the user has opted_in for neutralising their order or not. | boolean | required |
climes | This is amount of climes that are required to neutralize the footprint. | number | required |
Endpoint
/v3/integrations/vote/opt-in
Method
POST
Headers
{
'x-api-key' : 'API_KEY',
'Content-Type' : 'application/json'
}
If you use a static order id for carts and for orders,in which case you can pass the order id as the value for cart_id
.
Payload
{
"cart_id" : "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"climes" : 5,
"opted_in" : true
}
Resending the same cart_id again will update the old data with the latest data that is sent.
If you want to update the OptIn data for any cart_id
, just send the request again with the cart_id
for which the data needs to be updated along with the updated data for that request.
Response Parameters
Status Code
200
Response Data
{
message : "Opt-In data added successfully"
}
Sample Request
- cURL
- NodeJs
- Axios
- Python
- Php
curl --location --request POST 'BASE_URL/v3/integrations/vote/opt-in'
--header 'x-api-key: API_KEY'
--header 'Content-Type: application/json'
--data-raw '{
"cart_id" : "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"climes" : 5,
"opted_in" : true
}'
const fetch = require('node-fetch');
const url = 'BASE_URL/v3/integrations/vote/opt-in';
const apiKey = 'API_KEY';
const headers = {
'x-api-key': apiKey,
'Content-Type': 'application/json'
};
const body = JSON.stringify({
cart_id: '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d',
climes: 5,
opted_in: true
});
const options = {
method: 'POST',
headers: headers,
body: body
};
fetch(url, options)
.then(response => response.json())
.then(data => {
// Handle the response data
console.log(data);
})
.catch(error => {
// Handle any errors
console.error(error);
});
var axios = require('axios');
var data = JSON.stringify({
"cart_id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"climes": 5,
"opted_in": true
});
var config = {
method: 'post',
url: 'BASE_URL/v3/integrations/vote/opt-in',
headers: {
'x-api-key': 'API_KEY',
'Content-Type': 'application/json'
},
data : data
};
axios(config)
.then(function (response) {
console.log(JSON.stringify(response.data));
})
.catch(function (error) {
console.log(error);
});
import requests
import json
url = "BASE_URL/v3/integrations/vote/opt-in"
payload = json.dumps({
"cart_id": "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"climes": 5,
"opted_in": True
})
headers = {
'x-api-key': 'API_KEY',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('BASE_URL/v3/integrations/vote/opt-in');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'x-api-key' => 'API_KEY',
'Content-Type' => 'application/json'
));
$request->setBody('{
"cart_id" : "9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d",
"climes" : 5,
"opted_in" : true
}');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
Sample Response
Below are sample responses for the above request.
Responses
- Success - 200
- Failure - 400
{
"message": "Opt-In data added successfully"
}
{
"message": "Bad Request! Please send all the variables properly."
}