Answer the question
In order to leave comments, you need to log in
How to work with JSON-RPC 2.0?
Hello. I need to call the calculateShipping function from the API, but I don't understand how to implement it. Here is the API:
https://shiptor.ru/doc/
As I understand it, the JSON-RPC 2.0 standard is used. To do this, I connected the library:
https://github.com/fguillot/JsonRPC
1). How can I pass the headers?
Content-Type: application/json
x-authorization-token: your_API_key
Answer the question
In order to leave comments, you need to log in
$apiUrl = "https://api.shiptor.ru/public/v1";
$apiKey = "YOUR_KEY";
$client = new \JsonRPC\Client($apiUrl);
// Set headers
$client->getHttpClient()->withBeforeRequestCallback(function(HttpClient $client, $payload) {
$client->withHeaders([
"Content-Type: application/json",
"x-authorization-token: {$apiKey}"
]);
});
// Fetch something
$method = "calculateShipping";
$params = ['paramName'=>"paramValue"];
$result = $client->execute($method, $params);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question