Client code examples
Client applications communicate with a Codehooks API and database via a secure REST API. You can interface with Codehooks from most popular programming languages and platforms, such as: cURL, JavaScript, Python, PHP, Java, C#, Kotlin, R and Swift.
In the code examples shown below we use mystore-fafb
as an example Codehooks project name and dev
as a project data space. Replace this with your own project name, and use a valid API token (x-apikey
) or a JWT/JWKS integration (Bearer <token>
).
Code examples for popular programming languages
- cURL
- JavaScript
- Python
- C#
- PHP
- Java
- Swift
- Kotlin
- R
GET
documents from the salesorder collection.
curl --location 'https://mystore-fafb.api.codehooks.io/dev/salesorder?customerID=1234' \
--header 'x-apikey: 3c932310-3fab-4ba3-8102-b75ba0f05149'
POST
a new document to the salesorder collection.
curl --location 'https://mystore-fafb.api.codehooks.io/dev/salesorder' \
--header 'x-apikey: 3c932310-3fab-4ba3-8102-b75ba0f05149' \
--header 'Content-Type: application/json' \
--data '{
"customerID": 1234,
"productID": 21435465,
"quantity": 3,
"payment": "subscription"
}'
PATCH
(update) an existing document in the salesorder collection.
curl --location --request PATCH 'https://mystore-fafb.api.codehooks.io/dev/salesorder/9876' \
--header 'x-apikey: 3c932310-3fab-4ba3-8102-b75ba0f05149' \
--header 'Content-Type: application/json' \
--data '{
"quantity": 2,
"payment": "card"
}'
DELETE
a document in the salesorder collection.
curl --location --request DELETE 'https://mystore-fafb.api.codehooks.io/dev/salesorder/9876' \
--header 'x-apikey: 3c932310-3fab-4ba3-8102-b75ba0f05149'
GET
documents from the salesorder collection.
var myHeaders = new Headers();
myHeaders.append("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149");
var requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://mystore-fafb.api.codehooks.io/dev/salesorder?customerID=1234", requestOptions)
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.log('error', error));
POST
a new document to the salesorder collection.
var myHeaders = new Headers();
myHeaders.append("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"customerID": 1234,
"productID": 21435465,
"quantity": 3,
"payment": "subscription"
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://mystore-fafb.api.codehooks.io/dev/salesorder", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
PATCH
(update) an existing document (9876) in the salesorder collection.
var myHeaders = new Headers();
myHeaders.append("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149");
myHeaders.append("Content-Type", "application/json");
var raw = JSON.stringify({
"quantity": 2,
"payment": "card"
});
var requestOptions = {
method: 'PATCH',
headers: myHeaders,
body: raw,
redirect: 'follow'
};
fetch("https://mystore-fafb.api.codehooks.io/dev/salesorder/9876", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
DELETE
a document in the salesorder collection.
var myHeaders = new Headers();
myHeaders.append("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149");
var requestOptions = {
method: 'DELETE',
headers: myHeaders,
redirect: 'follow'
};
fetch("https://mystore-fafb.api.codehooks.io/dev/salesorder/9876", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
GET
documents from the salesorder collection.
import requests
url = "https://mystore-fafb.api.codehooks.io/dev/salesorder?customerID=1234"
payload = {}
headers = {
'x-apikey': '3c932310-3fab-4ba3-8102-b75ba0f05149'
}
response = requests.request("GET", url, headers=headers, data=payload)
print(response.text)
POST
a new document to the salesorder collection.
import http.client
import json
conn = http.client.HTTPSConnection("mystore-fafb.api.codehooks.io")
payload = json.dumps({
"customerID": 1234,
"productID": 21435465,
"quantity": 3,
"payment": "subscription"
})
headers = {
'x-apikey': '3c932310-3fab-4ba3-8102-b75ba0f05149',
'Content-Type': 'application/json'
}
conn.request("POST", "/dev/salesorder", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
PATCH
(update) an existing document (9876) in the salesorder collection.
import http.client
import json
conn = http.client.HTTPSConnection("mystore-fafb.api.codehooks.io")
payload = json.dumps({
"quantity": 2,
"payment": "card"
})
headers = {
'x-apikey': '3c932310-3fab-4ba3-8102-b75ba0f05149',
'Content-Type': 'application/json'
}
conn.request("PATCH", "/dev/salesorder/9876", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
DELETE
a document in the salesorder collection.
import http.client
conn = http.client.HTTPSConnection("mystore-fafb.api.codehooks.io")
payload = ''
headers = {
'x-apikey': '3c932310-3fab-4ba3-8102-b75ba0f05149'
}
conn.request("DELETE", "/dev/salesorder/9876", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
GET
documents from the salesorder collection.
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, "https://mystore-fafb.api.codehooks.io/dev/salesorder?customerID=1234");
request.Headers.Add("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
POST
(create) a new document to the salesorder collection.
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://mystore-fafb.api.codehooks.io/dev/salesorder");
request.Headers.Add("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149");
var content = new StringContent("{\n \"customerID\": 1234,\n \"productID\": 21435465,\n \"quantity\": 3,\n \"payment\": \"subscription\"\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
PATCH
(update) an existing document (9876) in the salesorder collection.
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Patch, "https://mystore-fafb.api.codehooks.io/dev/salesorder/9876");
request.Headers.Add("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149");
var content = new StringContent("{\n \"quantity\": 2,\n \"payment\": \"card\"\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
DELETE
a document in the salesorder collection.
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Delete, "https://mystore-fafb.api.codehooks.io/dev/salesorder/9876");
request.Headers.Add("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149");
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
GET
documents from the salesorder collection.
<?php
$client = new Client();
$headers = [
'x-apikey' => '3c932310-3fab-4ba3-8102-b75ba0f05149'
];
$request = new Request('GET', 'https://mystore-fafb.api.codehooks.io/dev/salesorder?customerID=1234', $headers);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
POST
(create) a new document to the salesorder collection.
<?php
$client = new Client();
$headers = [
'x-apikey' => '3c932310-3fab-4ba3-8102-b75ba0f05149',
'Content-Type' => 'application/json'
];
$body = '{
"customerID": 1234,
"productID": 21435465,
"quantity": 3,
"payment": "subscription"
}';
$request = new Request('POST', 'https://mystore-fafb.api.codehooks.io/dev/salesorder', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
PATCH
(update) an existing document (9876) in the salesorder collection.
<?php
$client = new Client();
$headers = [
'x-apikey' => '3c932310-3fab-4ba3-8102-b75ba0f05149',
'Content-Type' => 'application/json'
];
$body = '{
"quantity": 2,
"payment": "card"
}';
$request = new Request('PATCH', 'https://mystore-fafb.api.codehooks.io/dev/salesorder/9876', $headers, $body);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
DELETE
a document in the salesorder collection.
<?php
$client = new Client();
$headers = [
'x-apikey' => '3c932310-3fab-4ba3-8102-b75ba0f05149'
];
$request = new Request('DELETE', 'https://mystore-fafb.api.codehooks.io/dev/salesorder/9876', $headers);
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
GET
documents from the salesorder collection.
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.get("https://mystore-fafb.api.codehooks.io/dev/salesorder?customerID=1234")
.header("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149")
.asString();
POST
(create) a new document to the salesorder collection.
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.post("https://mystore-fafb.api.codehooks.io/dev/salesorder")
.header("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149")
.header("Content-Type", "application/json")
.body("{\n \"customerID\": 1234,\n \"productID\": 21435465,\n \"quantity\": 3,\n \"payment\": \"subscription\"\n}")
.asString();
PATCH
(update) an existing document (9876) in the salesorder collection.
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.patch("https://mystore-fafb.api.codehooks.io/dev/salesorder/9876")
.header("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149")
.header("Content-Type", "application/json")
.body("{\n \"quantity\": 2,\n \"payment\": \"card\"\n}")
.asString();
DELETE
a document in the salesorder collection.
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.delete("https://mystore-fafb.api.codehooks.io/dev/salesorder/9876")
.header("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149")
.asString();
GET
documents from the salesorder collection.
var request = URLRequest(url: URL(string: "https://mystore-fafb.api.codehooks.io/dev/salesorder?customerID=1234")!,timeoutInterval: Double.infinity)
request.addValue("3c932310-3fab-4ba3-8102-b75ba0f05149", forHTTPHeaderField: "x-apikey")
request.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
POST
(create) a new document to the salesorder collection.
let parameters = "{\n \"customerID\": 1234,\n \"productID\": 21435465,\n \"quantity\": 3,\n \"payment\": \"subscription\"\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://mystore-fafb.api.codehooks.io/dev/salesorder")!,timeoutInterval: Double.infinity)
request.addValue("3c932310-3fab-4ba3-8102-b75ba0f05149", forHTTPHeaderField: "x-apikey")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
PATCH
(update) an existing document (9876) in the salesorder collection.
let parameters = "{\n \"quantity\": 2,\n \"payment\": \"card\"\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "https://mystore-fafb.api.codehooks.io/dev/salesorder/9876")!,timeoutInterval: Double.infinity)
request.addValue("3c932310-3fab-4ba3-8102-b75ba0f05149", forHTTPHeaderField: "x-apikey")
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpMethod = "PATCH"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
DELETE
a document in the salesorder collection.
var request = URLRequest(url: URL(string: "https://mystore-fafb.api.codehooks.io/dev/salesorder/9876")!,timeoutInterval: Double.infinity)
request.addValue("3c932310-3fab-4ba3-8102-b75ba0f05149", forHTTPHeaderField: "x-apikey")
request.httpMethod = "DELETE"
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
GET
documents from the salesorder collection.
val client = OkHttpClient()
val request = Request.Builder()
.url("https://mystore-fafb.api.codehooks.io/dev/salesorder?customerID=1234")
.addHeader("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149")
.build()
val response = client.newCall(request).execute()
POST
(create) a new document to the salesorder collection.
val client = OkHttpClient()
val mediaType = "application/json".toMediaType()
val body = "{\n \"customerID\": 1234,\n \"productID\": 21435465,\n \"quantity\": 3,\n \"payment\": \"subscription\"\n}".toRequestBody(mediaType)
val request = Request.Builder()
.url("https://mystore-fafb.api.codehooks.io/dev/salesorder")
.post(body)
.addHeader("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149")
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()
PATCH
(update) an existing document (9876) in the salesorder collection.
val client = OkHttpClient()
val mediaType = "application/json".toMediaType()
val body = "{\n \"quantity\": 2,\n \"payment\": \"card\"\n}".toRequestBody(mediaType)
val request = Request.Builder()
.url("https://mystore-fafb.api.codehooks.io/dev/salesorder/9876")
.patch(body)
.addHeader("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149")
.addHeader("Content-Type", "application/json")
.build()
val response = client.newCall(request).execute()
DELETE
a document in the salesorder collection.
val client = OkHttpClient()
val mediaType = "text/plain".toMediaType()
val body = "".toRequestBody(mediaType)
val request = Request.Builder()
.url("https://mystore-fafb.api.codehooks.io/dev/salesorder/9876")
.method("DELETE", body)
.addHeader("x-apikey", "3c932310-3fab-4ba3-8102-b75ba0f05149")
.build()
val response = client.newCall(request).execute()
GET
documents from the salesorder collection.
library(RCurl)
headers = c(
"x-apikey" = "3c932310-3fab-4ba3-8102-b75ba0f05149"
)
res <- getURL("https://mystore-fafb.api.codehooks.io/dev/salesorder?customerID=1234", .opts=list(httpheader = headers, followlocation = TRUE))
cat(res)
POST
(create) a new document to the salesorder collection.
library(RCurl)
headers = c(
"x-apikey" = "3c932310-3fab-4ba3-8102-b75ba0f05149",
"Content-Type" = "application/json"
)
params = "{
\"customerID\": 1234,
\"productID\": 21435465,
\"quantity\": 3,
\"payment\": \"subscription\"
}"
res <- postForm("https://mystore-fafb.api.codehooks.io/dev/salesorder", .opts=list(postfields = params, httpheader = headers, followlocation = TRUE), style = "httppost")
cat(res)
PATCH
(update) an existing document (9876) in the salesorder collection.
library(RCurl)
headers = c(
"x-apikey" = "3c932310-3fab-4ba3-8102-b75ba0f05149",
"Content-Type" = "application/json"
)
params = "{
\"quantity\": 2,
\"payment\": \"card\"
}"
res <- getURLContent("https://mystore-fafb.api.codehooks.io/dev/salesorder/9876", customrequest = "PATCH", postfields = params, httpheader = headers, followlocation = TRUE)
cat(res)
DELETE
a document in the salesorder collection.
library(RCurl)
headers = c(
"x-apikey" = "3c932310-3fab-4ba3-8102-b75ba0f05149"
)
res <- httpDELETE("https://mystore-fafb.api.codehooks.io/dev/salesorder/9876", httpheader = headers, followlocation = TRUE)
cat(res)