In order to use our API, you need to get your x-auth-key and x-client-id first.
How to get x-client-id and x-auth-key
You can access API Keys to copy x-client-id and x-auth-key.
Do not show your x-auth-key to anyone else. If someone gains the access ot your x-auth-key, they can use your account as if they had your password. You can click on the Reset button to get a new one and invalidate the old one for security reasons.
Authentication
Generate a signature based on HMAC-SHA256 algorithm through the x-auth-key and x-client-id to ensure the integrity and security of the request. The request body and a timestamp can be signed to prevent replay attacks.
Example signature instance.
Clear body data without extra Spaces
Example signature method.
Example data to be sorted by field
Example request
replace you auth-key with your actual API ID and API Key.
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.TypeReference;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
public class JsonSorterUtils {
/**
* Converts the object into a sorted, compact JSON string。
*
* @param obj The object to be converted
* @return A compact sorted JSON string
*/
public static String objectToJsonSorted(Object obj) {
Map<String, Object> map = JSON.parseObject(JSON.toJSONString(obj), new TypeReference<Map<String, Object>>() {});
return JSON.toJSONString(sortMap(map));
}
/**
* Sort the Map and recursively sort the Jsonobjects in it
*
* @param map Map that needs to be sorted
* @return The sorted Map
*/
private static Map<String, Object> sortMap(Map<String, Object> map) {
if (map == null) return null;
// Sort the external fields using TreeMap
SortedMap<String, Object> sortedMap = new TreeMap<>(map);
// Iterate through the Map and sort each JSONObject recursively
for (Map.Entry<String, Object> entry : sortedMap.entrySet()) {
if (entry.getValue() instanceof JSONObject) {
// If it is JSONObject, it is converted to Map before sorting
Map<String, Object> nestedMap =
JSON.parseObject(entry.getValue().toString(), new TypeReference<Map<String, Object>>() {});
entry.setValue(sortMap(nestedMap));
} else if (entry.getValue() instanceof Map) {
// If it is a Map, it is sorted recursively
entry.setValue(sortMap((Map<String, Object>) entry.getValue()));
}
}
return sortedMap;
}
}
import json
class JsonSorter:
@staticmethod
def object_to_json_sorted(obj):
obj_dict = JsonSorter._convert_to_dict(obj)
sorted_dict = JsonSorter._sort_dict(obj_dict)
return json.dumps(sorted_dict, separators=(',', ':'))
@staticmethod
def _convert_to_dict(obj):
if isinstance(obj, dict):
return obj
elif hasattr(obj, '__dict__'):
return obj.__dict__
elif isinstance(obj, str):
return json.loads(obj)
else:
raise ValueError("Unsupported type")
@staticmethod
def _sort_dict(d):
sorted_items = sorted(d.items())
sorted_dict = {}
for key, value in sorted_items:
if isinstance(value, dict):
sorted_dict[key] = JsonSorter._sort_dict(value)
else:
sorted_dict[key] = value
return sorted_dict