S
S
Sergey2018-10-17 06:57:58
PHP
Sergey, 2018-10-17 06:57:58

How to send data in body via curl in php?

The task is to connect the site to the api of another site.
Here's what I know.


Requests.
All requests must contain a header (Header) Authorization, in the value of which there must be a token. You can also add a language to the header, after which response descriptions will be in the appropriate language, for example:
Authorization: Token 4443a98e3389a2d90b05da7eae342e5f61ffd39c
Accept-Language: en (default=ru, en, kk)
Responses
All responses are returned in JSON format

I am using curl
$url = "https://testpay.post.kz/api/v0/orders/payment/";

$headers = array();
$headers[] = "Accept: application/json";
$headers[] = "Content-Type: application/json";
$headers[] = "Content-length: 0";
$headers[] = "Authorization: Token 9999079c286bfc020045a692c184246cee95bfe9";

$params = Array(
  "amount"=>2000,
  "back_link"=>"kazpostpay.pr/success.php",
  "payment_webhook"=>"http://testpay.pruk.kz/webhook.php", 
  "email"=>"[email protected]");

$params = json_encode($params);

$crl = curl_init();
curl_setopt($crl, CURLOPT_HTTPHEADER,$headers);
curl_setopt($crl, CURLOPT_URL, $url);
curl_setopt($crl, CURLOPT_POST,true);
curl_setopt($crl, CURLOPT_POSTFIELDS, $params);

$rest = curl_exec($crl);

curl_close($crl);

At the output I get the answer: {"success":false,"errors":{"amount":["This field is required."]}}
api thinks that I sent an empty "amount".
Also from the documentation:
Test server data
token -- ask the project manager --
postman_file -- ask the project manager --
key -- ask the project manager -- "DEMO" is used for the test server
The api developers answered that I should send the data in body. I was also provided with 2 files (postman_file). One of them, the second one is too big.
{
"id": "b2af3619-7698-fd08-851f-24fb2403c995",
"name": "TEST SERVER",
"values": [
{
"enabled": true,
"key": "url",
"value": " https://testpay.post.kz ",
"type": "text"
},
{
"enabled": true,
"key": "token",
"value": "9999079c286bfc020045a692c184246cee95bfe9",
"type": "text "
},
{
"enabled": true,
"key": "",
"value": "",
"type": "text"
}
],
"timestamp": 1516888480700,
"_postman_variable_scope": "environment",
"_postman_exported_at": "2018-02-08T03:27:04.142Z",
"_postman_exported_using": "Postman/5.5.1"
}

Questions:
How to send data to body?
Is it possible that I missed something in the headers?
Why do I need 2 files (postman) and how can I send them?
This is the first time I've come across such api.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-10-17
@seregali

Why do I need 2 files (postman) and how can I send them?

what is Postman - do you even know?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question