我得到错误:
{"message": "Method Not Allowed", "status": 405}
尝试创建新的接收地址时。根据API文档,我的API密钥具有"recv"权限。
这是API文档中关于向端点发送参数的说明。唯一需要的参数是帐户,我试图在cURL
中POST
。
我怀疑我没有正确设置cURL
选项。
$endpoint='/v1/new/receive';
$url='https://api.coinkite.com'.$endpoint;
$sign = coinkitesign($endpoint);
$API_KEY = COINKITEAPIKEY;
$ch = curl_init($url);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("X-CK-Key: {$API_KEY}", "X-CK-Sign: {$sign[0]}", "X-CK-Timestamp: {$sign[1]}"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array('account' => '933xxxxx2A-Axxxx5','memo' => 'test1234');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
您需要做PUT
请求,而不是POST
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
你应该在API文档中反复检查你接受的方法:https://docs.coinkite.com/api/new-update.html
实际上,解决方案是使用put——这是我需要的代码:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
$data = array('account' => 'xxxxxx-xxxxxx','memo' => 'test1234');
$data = json_encode($data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);