I'm new to curl in PHP... and I was just wondering how to transform this curl command into PHP:
curl https://ancient-test.chargebee.com/api/v1/portal_sessions \
-u test_rdsfgfgfddsffds: \
-d customer[id]="EXAMPLE" \
-d redirect_url="https://yourdomain.com/users/3490343"
Right now I've got:
$post_data['customer']['id'] = "EXAMPLE";
$post_data['redirect_url'] = "http://" . SITE_URL . "/myaccount/";
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://ancient-test.chargebee.com/api/v1/portal_sessions");
curl_setopt($ch,CURLOPT_USERPWD,"test_rdsfgfgfddsffds:");
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_data);
$output = curl_exec($ch);
curl_close($ch);
But I get the error message:
{"errors":[{"message":"There were errors while submitting"},{"param":"customer[id]","message":"cannot be blank"}]}
Thanks for your help!
Jan
$customer['id']empty?curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($post_data));or create the first-dimension array key by hand. However, your current code should generate an array-to-string conversion warning. Are you sure the code shown is the one you test with?