For those of you that use PHP, here is a quick script you can use to send data to your documents and data routes.
$data = array( 'OrgName' => 'Org 1', 'OrgAddress' => 'Address 1', 'OrgCity' => 'Orlando', 'OrgState' => 'FL', 'OrgZip' => '32819' ); $json_data = json_encode($data); $url = 'https://www.webmerge.me/merge/10690/me1ket'; //open connection $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json', 'Content-Length: ' . strlen($json_data)) ); //execute post $result = curl_exec($ch); //close connection curl_close($ch); if ($result) { $response = 'Document created successfully. Check WebMerge for more details.'; } else { $response = 'No documents created.'; } echo $response;
Combine PDF Documents
If you'd like to send all your data for multiple merges (of the same document) at once and receive back a "combined" document with all of the individual merges as separate pages, you just need to make one minor adjustment to the code above
$data = array( '_combine' => array( array( 'OrgName' => 'Org 1', 'OrgAddress' => 'Address 1', 'OrgCity' => 'Orlando', 'OrgState' => 'FL', 'OrgZip' => '32819' ), array( 'OrgName' => 'Org 2', 'OrgAddress' => 'Address 2', 'OrgCity' => 'Orlando', 'OrgState' => 'FL', 'OrgZip' => '32819' ), ) );
Notice the individual data sets are wrapped in an array that has a key "_combined". This tells the merge system to create a document with each array inside the _combined key and then create a single PDF
Comments
This works really great especially for testing from a PHP harness that calls another API (we're using Wild Apricot). Is there a way to redirect to the completed PDF on screen rather than just echo a success/fail response?
Hi Alex,
Yes, you can add a "download=1" parameter to your Merge URL and we'll return the document in the response (instead of JSON), then you can display the file to the user like this:
header('Content-Description: File Transfer');
header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="The File.pdf";');
header("Content-Length: ".strlen($response));
print $response;
Is there a way to "post" the data to a data capture form without submitting the form (rather pre-populating some of the fields) from php?
Hi Don,
Can you send the data via "GET" (URL parameters)? That would allow you to pre-populate the fields on the data capture form. Unfortunately, a POST request will cause the form to be submitted automatically.
Thanks,
Please sign in to leave a comment.