HomeCoding & Programming

Call vPress Coreprint “getproof” Web Service using POST method

Call vPress Coreprint “getproof” Web Service using POST method
Like Tweet Pin it Share Share Email

Before 3 Days, A task assigned to me. Task is related to  vPress CorePrint API  (Web2Print service).
In that what I have to do is, Client has uploaded lots of products in vPress coreprint.
The products are 3 types photo frames, wallpapers strips and one more.

 

Client have provided me a PDF for understanding the API and to let me know how to communicate with vPress API.
There are various services defined in that, some are using GET methods and some POST & some other are using PUT.

 

I have tested the GET API as the example given in the PDF and it also worked for me.
But during the service call using POST method I was stacked I have to pass some parameters using a form(in the website) and have to pass this information to the web service call using the POST method and after a successful call it return me a product image(Photo Frame).

 

Like I have to pass the information like the background colour  theme, frame name, size and it should returned me back the photo frame image(client have uploaded in the coreprint) either in the image format or in PDF.

 

I have tried a lot and have spent 2 days but not find the way it works, and have mailed many time to support but not got the proper solution.
This time Google also not supported me a lot 🙁

 

Finally someone suggested me to use cURL with PHP to post json data and It works for me.

Below are the codes that works finally 🙂 hope this will also work for you.

If the cURL returns back either a Image or PDF or we can say that if the cURL not return plain text.
Then we have to set some headers to view the result.


<?php

$key         = "licence_key";
$username    = "your_username";
$pass        = "your_password"; 
$tmp         = $username.":".$pass;
$productid   = "your_productid";
$service     = "getproof";
 
 
$postdata    = $_POST;                                                                
$data_string = json_encode($postdata);                                                                                  
$url         = "http://www.coreprint.net/ws/jsonfactory/?key=".$key."&service=".$service."&productid=".$productid;
 
 
$ch = curl_init($url);                                                                     
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                    
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                     
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                         
    'Content-Type: text/html',
    'Authorization: Basic '.base64_encode($tmp),
    'Content-Length: ' . strlen($data_string))                                                                      
);
$result = curl_exec($ch);
 
 
curl_close($ch);
/*Set header to display the image (returned by curl) in the browser*/
header('Content-type: image/jpeg');
 
 
/*Set header to set the content type PDF (returned by curl) in the browser*/
/*
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename=testfile.pdf');
readfile('pdfgeneratedbytheserver.pdf'); 
*/ 
 
 
echo $result;

?>

 

Headers for viewing the image returned by cURL.

/*Set header to display the image (returned by curl) in the browser*/
header('Content-type: image/jpeg');

Headers for viewing the PDF returned by cURL.

/*Set header to set the content type PDF (returned by curl) in the browser*/
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename=testfile.pdf');
readfile('pdfgeneratedbytheserver.pdf'); 

Hope this all will help you, let me know by your comment if you still face any issue in implementing vPress coreprint API with post method.

 

Comments (1)

  • Thanks for this, although we recently did an integration into Vpress’ Coreprint and did not encounter these issues. I guess they must have changed how this works as it was a lot easier to do than you have described here.

Comments are closed.