Error while creating Hosted Page for New Subscription via Hosted Page API

Error while creating Hosted Page for New Subscription via Hosted Page API

Hi Team,

I get a  HTTP request failed! HTTP/1.1 400 Bad Request error while trying to create a hosted page for new subscription using Hosted Page API

Here's my code:

  1. $data = array(
  2. 'customer'=>array('display name'=>'Mr. Hash Tiwari','first_name'=>'Tarun','last_name'=>'Tiwari','email'=>"tarun@noemail.com",'mobile'=>'99999999999'),
  3. 'plan'=>array('plan_code'=>'Small'),
  4. 'custom_fields'=>array('variant'=>'Chicken'),
  5. 'reference_id'=>'2222222'
  6. );

  7. $data = json_encode($data);

  8. $context = array(
  9.   'http'=>array(
  10.     'method'=>"POST",
  11.     'header'=>"Content-Type: application/json;charset=UTF-8\r\n" .
  12. "Content-Length: ".strlen($data)."\r\n".
  13. "X-com-zoho-subscriptions-organizationid: 639344623\r\n" .
  14. "Authorization: Zoho-authtoken xxxxxxxxxxxxxxxxxxxxxxxxx\r\n",
  15. 'content'=>$data
  16. )
  17. );

  18. $context = stream_context_create($context);
  19. // Open the file using the HTTP headers set above
  20. $file = file_get_contents("https://subscriptions.zoho.com/api/v1/hostedpages/newsubscription", false, $context);

  21. echo $file;