L
L
linuxnb2017-09-03 09:51:21
PHP
linuxnb, 2017-09-03 09:51:21

Why is json not being sent via CURL POST (PHP)?

Hello, I can’t send a request to QIWI API using PHP using Curl (Post)
By mistake, I realized that I was not passing Json correctly, but somehow I can’t solve this problem ((
{"message":"Invalid Json: No content to map due to end-of-input\n at [Source: [email protected]; line: 1, column: 0]"}1

$data = '{"id":"83278954723985","sum":{"amount":1.50,"currency":"643"},"paymentMethod":{"type":"Account","accountId":"643"},"comment":"test","fields":{"account":"+79024049398"}';
if ($curl = curl_init()) {
    curl_setopt($curl, CURLOPT_URL, 'https://edge.qiwi.com/sinap/api/v2/terms/99/payments');

    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer api_key','Content-type: application/json','Host: edge.qiwi.com'));
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_decode($data));
    echo $response = curl_exec($curl);
    curl_close($curl);
}

UDP: I've just discovered CURL, and I don't really understand JSON yet. do not judge strictly)
Thanks in advance for your help!)
link to qiwi api
https://developer.qiwi.com/ru/qiwicom/index.html#p2p

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2017-09-03
@linuxnb

Well, it is clearly written - Invalid Json. Your $data is missing a closing curly brace at the end.
Now: ..."+79024049398"}.
Should be: ..."+79024049398"}}.

L
linuxnb, 2017-09-03
@linuxnb

In response, I received
a Catchable fatal error: Object of class stdClass could not be converted to string
HERE is the line
curl_setopt($curl, CURLOPT_POSTFIELDS, json_decode($data));
found an error, removed the decode, tupanul.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question