# Wednesday, 21 August 2013

We've had several requests for an example on using our SOAP API, so decided to throw one together for you to get an idea of how it works.

The example below will send PDF documents as a letter with a cover letter which is written as a formatted HTML string (see the LetterBody attribute below).

To make more use of this example and to adapt it to your needs you may need to look at the Letter Pricing API along with the country code list which can all be found here.

If you would like us to advise you on what are the best options to use for postage and paper usage please contact us.

   1:  <?php
   2:   
   3:  $client = new SoapClient("https://www.pc2paper.co.uk/lettercustomerapi.svc?wsdl");
   4:   
   5:  // Your PC2Paper Username and Password go below
   6:  $pc2paperUsername = "username";
   7:  $pc2paperPassword = "password";
   8:   
   9:  //First we upload a PDF we wish to attach to our letter
  10:   
  11:  $file = file_get_contents("C:\tempfiles\mytestfile.pdf");
  12:   
  13:  //We give the pdf a friendly name
  14:  $parametersUpload->filename = "mytestFile.pdf";
  15:  $parametersUpload->fileContent = $file;
  16:  $parametersUpload->username=$pc2paperUsername;
  17:  $parametersUpload->password=$pc2paperPassword;
  18:   
  19:  //We submit our PDF to PC2Paper
  20:  $uploadedFileResult = $client->UploadDocument($parametersUpload);
  21:   
  22:  // Not the above return value contains the following
  23:  // $uploadedFileResult->UploadDocumentResult->ErrorMessages  (A a string array of any errors that took place)
  24:  // $uploadedFileResult->UploadDocumentResult->FileCreatedGUID (The created files GUID)0
  25:  // $uploadedFileResult->UploadDocumentResult->Status (OK or ERROR, if error check ErrorMessages array
  26:   
  27:  //After our PDF has been submited we get a GUID which we store in an array to use with our letter below.
  28:  //Note you can attach multiple PDF's to your letter by adding to this array.
  29:  $fileGuidArray =  array($uploadedFileResult->UploadDocumentResult->FileCreatedGUID);
  30:   
  31:   
  32:  // ********** The actual Letter.
  33:  // We put an address together
  34:  $address->ReceiverName = "Tom Smith";
  35:  $address->ReceiverAddressLine1 = "Line 1 ";
  36:  $address->ReceiverAddressLine2 = "Line 2";
  37:  $address->ReceiverAddressTownCityOrLine3 = "My Town";
  38:  $address->ReceiverAddressCountyStateOrLine4 = "County";
  39:  $address->ReceiverAddressPostCode = "ZZ1 2ZZ";
  40:   
  41:  // Add the address to an address array
  42:  $addressArray = array($address);
  43:   
  44:  //Add the address array to our letter
  45:  $letter->Addresses = $addressArray ;
  46:   
  47:  //Setup our postage options (use the LetterPosting API for these values 
  48:  //or ask us and we will be happy to provide the values based on your needs)
  49:   
  50:   
  51:  // 1=UK , 240=US for a list of more please refer to country.csv file from the API section of our website.
  52:  $letter->ReceiverCountryCode = 1; 
  53:   
  54:  $letter->IncludeSenderAddressOnEnvelope = true;
  55:  $letter->Postage = 3; //UK First Class
  56:  $letter->Paper = 1;  // B&W Single Sides print
  57:  $letter->Extras = 0;
  58:  $letter->Envelope = 1; //Simple DL envelope
  59:  $letter->Pages = 2;
  60:  $letter->FileAttachementGUIDs = $fileGuidArray;
  61:   
  62:  $letter->SenderAddress = "Peter Smith\nMy Town";
  63:   
  64:  //This is the cover letter of your letter. Leave this null if you do not want a cover letter
  65:  //You may use formatted HTML in here to format your letter.
  66:  $letter->LetterBody = "<p>Hi Tom,</p> <p>This is a letter sent from PHP!</p>";
  67:   
  68:   
  69:  $parameters->letterForPosting = $letter;
  70:   
  71:  // Your PC2Paper username and password
  72:  $parameters->username = $pc2paperUsername;
  73:  $parameters->password = $pc2paperPassword;
  74:   
  75:  $result = $client->SendSubmitLetterForPosting($parameters);
  76:   
  77:  // The return object will give you the following
  78:  // $result->SendSubmitLetterForPostingResult->CostOfLetter
  79:  // $result->SendSubmitLetterForPostingResult->ErrorMessages  (any errors that took place)
  80:  // $result->SendSubmitLetterForPostingResult->FundsLeftInYourAccount
  81:  // $result->SendSubmitLetterForPostingResult->LetterId
  82:  // $result->SendSubmitLetterForPostingResult->Status (OK if everything went ok or ERROR, if error check the ErrorMessages array)
  83:   
  84:   
  85:  print_r($result);
  86:  ?>
posted on Wednesday, 21 August 2013 21:02:50 (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Monday, 04 May 2009

The PC2Paper API documentation has been updated to version 3. The API now enables you to associate costs from our Letter Pricing API with letters. There is also a .NET C# example of how to use the XML RPC interface for sending PDF documents.

To find out more click here..

posted on Monday, 04 May 2009 15:27:07 (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Saturday, 07 March 2009

PC2Paper provides two letter sending API's and one Letter Pricing API (please see below)

PC2Papers API Letter Sending Interfaces

PC2Paper has two letter sending API interfaces available. One interface is a simple back end form post interface that only accepts text input (our most popular) and the other is a back end XML RPC interface that only accepts PDF and MS Word documents.

Form Post Interface

The Form Post Interface (FPI) is our most popular because of how simple it is to setup. If you have ever created a backend form interface to integrate with services such as PayPal and World Pay then you already have most of the skills you need to use the FPI. Simply speaking the FPI accepts a form post from either a normal webpage or a back end server to authenticate you, you provide your PC2Paper username and password to it and that is how the site knows who to bill the cost of the letter to. To use the interface and to find out more download the PC2PaperFPI pack.

 

XML RPC Interface

The PC2Paper XML RPC Interface is a bit more advanced than the form post interface and enables the sending of PDF and Word documents from server to server or desktop application to PC2Paper. Inside the PC2PaperXMLRPC pack we provide you with the sample XML the interface is expecting and a compiled (optional) VB 6 DLL called PC2PaperRemote.DLL which you can call instead of trying to create the XML the interface is expecting yourself. You should be able to use PC2PaperRemote.DLL from most COM aware languages such as VB, ASP, Delphi, .NET etc.

To use the PC2PaperRemote.DLL you will need to install MSXML if it is not already installed on the machine you intend to use it from. However if you prefer to generate the XML yourself and Base64 encode the file you wish to send into the XML, the format of the XML file can be found in the file XMLFormat.txt which can be found in the PC2PaperXMLRPC.

Letter Pricing API

PC2Paper provide an XML based interface that enables you to workout the price of your letter before sending it. This is useful for websites that resell our service and would like to know how much to bill the customers before actually sending the letter. To get started you can download the documentation for our interface here. You can also download the country code file, a csv you will need to lookup country codes.

posted on Saturday, 07 March 2009 11:03:34 (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback
# Friday, 12 December 2008

PC2Paper have released a new Letter Pricing API which enables you to do real time price queries on letters before they are sent from your own system. You may find this useful if you are reselling the PC2Paper service and would like to provide your customers with all the pricing options available such as special delivery, different printing options, envelope selections, printing station selection etc. Given all these options the PC2Paper Letter Pricing API will give you a price for your letter which you can then use to bill your user.

For more about Letter Pricing API, please visit the API section of our web site.

posted on Friday, 12 December 2008 17:43:41 (GMT Standard Time, UTC+00:00)  #    Comments [0] Trackback
# Saturday, 18 August 2007

We have now launched a Developer section on www.pc2paper.co.uk to help developers create new applications and integrate their existing back end systems with PC2Paper's API interface, enabling easier sending of real letters from the Internet using our service.

The area consists of a chat section for developers to raise questions with us and other developers and an API documentation section. All these features will also be backed up with updates from our blog site www.pc2paper.org.

There are no sign up fees to use our API interface, it is enabled on all PC2Paper accounts as standard. If you are a business or just a novice programmer who would like to integrate with our service please visit our Developer section.

posted on Saturday, 18 August 2007 10:24:05 (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback
# Wednesday, 09 May 2007

I had a chat with one of our technical guys Rob Forber yesterday about PC2Papers API interfaces and how he had just finished helping one our customers with a Delphi interface into PC2Paper. Now I'm not a technical person and all I know is that Delphi is another programming language and that he was excited by the accomplishment.

My interest is that we have helped another of our customers to interface their back office systems with our service.

For those who don't know PC2Paper API or Application Interface enables our customers to integrate their own back office systems (systems they use to run their businesses) and websites so that they can automatically send letters via our service. Over the coming months I will be getting Rob to write a few articles about how you can write your own interfaces into PC2Paper.

If you would like to know before then, please contact us

posted on Wednesday, 09 May 2007 16:10:03 (GMT Daylight Time, UTC+01:00)  #    Comments [0] Trackback