A
A
a_palanski2018-08-26 16:55:30
API
a_palanski, 2018-08-26 16:55:30

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}";

api_key and api_secret I prescribe and when the script is executed, there is no response data string (0) ""
Tell me in which direction to move in order to do everything right? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-08-26
@a_palanski

here you train
in Kurla, turn on debugging, VERBOSE = 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question