2012-05-22 4 views
0

API에서 필요로하는 데이터를 올바르게 보내지 못했을 것으로 생각됩니다. 내가 뭘 잘못하고 있는거야?PHP를 통해 Chargify에 데이터를 올바르게 게시 할 수 없습니다. cURL

$ch = curl_init("https://test.chargify.com/customers.json"); 

$data = array(
    'first_name' => 'Test', 
    'last_name' => 'User', 
    'email' => '[email protected]' 
); 

$data = json_encode($data); 

curl_setopt_array($ch, array(
    CURLOPT_USERPWD => "yyyyyyyyyyyyyyy:x", // assume this is correct 
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_CUSTOMREQUEST => "POST", 
    CURLOPT_POSTFIELDS => $data, 
    CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json', 
    'Content-Length: ' . strlen($data) 
) 
)); 

$output = curl_exec($ch); 
curl_close($ch); 

{ 
errors: [ 
     "First name: cannot be blank.", 
     "Last name: cannot be blank.", 
     "Email address: cannot be blank." 
    ] 
} 

가 여기에 API에 대한 문서의 반환 http://docs.chargify.com/api-customers

답변

1

이 시도 :

$data = array('customer' => array(
    'first_name' => 'Test', 
    'last_name' => 'User', 
    'email' => '[email protected]' 
)); 
+1

신선한 눈의 힘을! 고마워 친구. –

관련 문제