Hi,
I'm trying to integrate the 'Cover Generation API' and the 'One-piece cover/spine width calculation API' with PHP cUrl and I'm getting in both cases the following error: "no data was posted".
Here is my code, maybe somebody can help me figuring out what I'm doing wrong:
A couple things I noticed that should get your code working with the cover generation api.
1 - You'll need to use curl_setopt to set an http header in your curl request. Try adding the following line :
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/JSON'));
2 - Creating an array of post data does not seem to be working. I did the following:
$postData = "$this->api_key=$api_key&data=" . json_encode($data);
3 - Finally the cover generation api does support coil bound books at the moment. Try changing this value to 'perfect'.
I determined a while ago why the array of POST data doesn't work with PHP cURL. The issue is that when given an array for the POST data, cURL automatically sends a multipart-mime message, which the server doesn't parse properly. This is a bug that we will look into fixing in a future iteration.
Hi,
I'm trying to integrate the 'Cover Generation API' and the 'One-piece cover/spine width calculation API' with PHP cUrl and I'm getting in both cases the following error: "no data was posted".
Here is my code, maybe somebody can help me figuring out what I'm doing wrong:
For the cover width calculation:
$url = "https://apps.lulu.com/api/pdfgen/covers/v1/calculateSize";
$data = array( "numberOfPages" => 32,
"color" => false,
"trimSize" => "A5",
"bindingType" => "coil",
"paperType" => "regular");
$postData = array( 'api_key' => $this->api_key,
'data' => json_encode($data),
'responseType' => 'json');
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
curl_close($ch);
echo $response;
For the cover generation I'm using the same structure, changing only the $url and the $data
Message edited by Photis Patriotis 2 years ago
Keith Shaw – 2 years ago
Hi Photis,
A couple things I noticed that should get your code working with the cover generation api.
1 - You'll need to use curl_setopt to set an http header in your curl request. Try adding the following line :
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/JSON'));
2 - Creating an array of post data does not seem to be working. I did the following:
$postData = "$this->api_key=$api_key&data=" . json_encode($data);
3 - Finally the cover generation api does support coil bound books at the moment. Try changing this value to 'perfect'.
Hope this helps let us know if it works for you.
Ryan Bloom – 2 years ago
I determined a while ago why the array of POST data doesn't work with PHP cURL. The issue is that when given an array for the POST data, cURL automatically sends a multipart-mime message, which the server doesn't parse properly. This is a bug that we will look into fixing in a future iteration.
Ryan
Photis Patriotis – 2 years ago
Thanks Keith! it worked perfectly! Does the api support saddle-stitch bound books?
Daniel Wideman – 2 years ago
Yes, saddle stitch is supported. See http://developer.lulu.com/docs/read/pubapi/Getting_Started#physical_attributes.