Answer the question
In order to leave comments, you need to log in
How to send an API request and get a response?
Good afternoon, tell me how to correctly form a request and get a response via the API?
There is an example:
<?php
$api_key = "**** YOUR API KEY ****";
$api_secret = "**** YOUR API SECRET ****";
$prefix = "/api/v3";
// GET method example
$endpoint = '/[email protected]';
$data = $api_key . "GET" . $prefix . $endpoint;
$hmac = hash_hmac("SHA256", $data, $api_secret);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://dev.safecrow.ru" . $prefix . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "{$api_key}:{$hmac}");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$body = curl_exec($ch) . "\n";
print_r(curl_getinfo($ch));
curl_close($ch);
echo "BODY: {$body}";
// POST method example
$json = [ 'email' => '[email protected]' ];
$endpoint = '/users';
$data = $api_key . "POST" . $prefix . $endpoint . json_encode($json);
$hmac = hash_hmac("SHA256", $data, $api_secret);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://dev.safecrow.ru" . $prefix . $endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,json_encode($json));
curl_setopt($ch, CURLOPT_USERPWD, "{$api_key}:{$hmac}");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$body = curl_exec($ch) . "\n";
print_r(curl_getinfo($ch));
curl_close($ch);
echo "BODY: {$body}";
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question