Would you like to get updates about each order? Create a URL that will receive POST events, and
use this
function to register it. If you choose not to implement this, then you can still request the current
status on any (or all) order.
$data = ['postbackurl' => 'https://coberapi.com/api/1.0/postback.php'];
$ch = curl_init('https://coberapi.com/api/1.0/register');
$headers = array(
"Accept: application/json",
"Authorization: Bearer YOURTOKEN",
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
const https = require('https');
const data = {
postbackurl: 'https://coberapi.com/api/1.0/postback.php'
};
const headers = {
'Accept': 'application/json',
'Authorization': 'Bearer YOURTOKEN'
};
const options = {
hostname: 'coberapi.com',
path: '/api/1.0/register',
method: 'POST',
headers: headers
};
const req = https.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
console.log(responseData);
});
});
req.write(JSON.stringify(data));
req.end();
using System;
using System.IO;
using System.Net;
using System.Text;
class Program
{
static void Main()
{
string url = "https://coberapi.com/api/1.0/register";
string token = "YOURTOKEN";
string data = "{\"postbackurl\":\"https://coberapi.com/api/1.0/postback.php\"}";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.Headers.Add("Authorization", "Bearer " + token);
using (StreamWriter writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(data);
}
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream responseStream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
string responseData = reader.ReadToEnd();
Console.WriteLine(responseData);
}
}
}
import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class Main {
public static void main(String[] args) throws IOException {
String url = "https://coberapi.com/api/1.0/register";
String token = "YOURTOKEN";
String data = "{\"postbackurl\":\"https://coberapi.com/api/1.0/postback.php\"}";
URL urlObject = new URL(url);
HttpURLConnection connection = (HttpURLConnection) urlObject.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Authorization", "Bearer " + token);
try (OutputStream os = connection.getOutputStream()) {
byte[] input = data.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} else {
System.out.println("HTTP request failed with response code: " + responseCode);
}
}
}
Here is a very simple file that I can use to receive feedback from orders. I saved it as
api/postback.php