function post($url, $parameters, $accessToken = null) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($parameters));
if( ! is_null($accessToken)) {
$headers = [
"Content-Type: application/json",
"Authorization: Bearer {$accessToken}"
];
} else {
$headers = [
'Content-Type: application/json',
];
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$return['result'] = json_decode(curl_exec($ch));
$return['code_http'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $return;