Header Values
The most relevant REST request header values for our backend REST APIs are the following:
| Field Name | Description | Example Values | Usage Comment |
|---|---|---|---|
Accept | Format of the function call response that is desired. | application/json or application/xml | Setting a value is required. |
Content-Type | Format of the request content. | application/json or application/xml | Required for POST but not for GET. |
In the following example, the requested resource is a JSON object:
curl --request POST \
--url 'https://rest.cleverbridge.com/urlgenerator/generateusersessionurl' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'authorization: Basic YOUR_BASE64_ENCODED_CREDENTIALS' \
--data '{
"TargetUrl": "https%3A%2F%2Fwww.cleverbridge.com%2F864%2F%3Fscope%3Dcheckout%26amp%3Bcart%3D97771%26amp%3Blanguage%3Den%26amp%3Bcurrency%3DUSD%26amp%3Bx-source%3Dwebsite-visit-05.2019
}'import requests
url = "https://rest.cleverbridge.com/urlgenerator/generateusersessionurl"
headers = {
"accept": "application/json",
"content-type": "application/json",
"authorization": "Basic YOUR_BASE64_ENCODED_CREDENTIALS"
}
payload = {
"TargetUrl": "https%3A%2F%2Fwww.cleverbridge.com%2F864%2F%3Fscope%3Dcheckout%26amp%3Bcart%3D97771%26amp%3Blanguage%3Den%26amp%3Bcurrency%3DUSD%26amp%3Bx-source%3Dwebsite-visit-05.2019"
}
response = requests.post(url, json=payload, headers=headers)
print(response.json())
const https = require("https");
const url = "https://rest.cleverbridge.com/urlgenerator/generateusersessionurl";
const headers = {
Accept: "application/json",
"Content-Type": "application/json",
Authorization: "Basic YOUR_BASE64_ENCODED_CREDENTIALS",
};
const data = JSON.stringify({
TargetUrl:
"https%3A%2F%2Fwww.cleverbridge.com%2F864%2F%3Fscope%3Dcheckout%26amp%3Bcart%3D97771%26amp%3Blanguage%3Den%26amp%3Bcurrency%3DUSD%26amp%3Bx-source%3Dwebsite-visit-05.2019",
});
const options = {
method: "POST",
headers: {
...headers,
"Content-Length": Buffer.byteLength(data),
},
};
const req = https.request(url, options, (res) => {
let body = "";
res.on("data", (chunk) => {
body += chunk;
});
res.on("end", () => {
try {
console.log(JSON.parse(body));
} catch (e) {
console.log(body);
}
});
});
req.on("error", (err) => {
console.error(err.message);
});
req.write(data);
req.end();
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
public class CleverbridgeApi {
public static void main(String[] args) throws Exception {
URL url = new URL("https://rest.cleverbridge.com/urlgenerator/generateusersessionurl");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("accept", "application/json");
con.setRequestProperty("content-type", "application/json");
con.setRequestProperty("authorization", "Basic YOUR_BASE64_ENCODED_CREDENTIALS");
con.setDoOutput(true);
String json = "{ \"TargetUrl\": \"https%3A%2F%2Fwww.cleverbridge.com%2F864%2F%3Fscope%3Dcheckout%26amp%3Bcart%3D97771%26amp%3Blanguage%3Den%26amp%3Bcurrency%3DUSD%26amp%3Bx-source%3Dwebsite-visit-05.2019\" }";
try (OutputStream os = con.getOutputStream()) {
os.write(json.getBytes("utf-8"));
}
BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"));
StringBuilder response = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
response.append(line.trim());
}
System.out.println("Response: " + response.toString());
}
}