Get PDF Response
2 min
The request includes the following parameters.
Field Name | Data Type | Description |
|---|---|---|
referenceId | string | Internal Id of the Transaction |
type | string | Pass the type of the Xero Transaction (invoice/ bill/ purchaseorder/ creditnote). |
Supported Transactions Types:
- Invoice - Pass the type as invoice
- Bill - Pass the type as bill
- Purchase Order - Pass the type as purchaseorder
- Credit Note - Pass the type as creditnote
Map<String, Object> invoiceFiltersMap = new Map<String, Object>();
invoiceFiltersMap.put('referenceId', 'e6f5564e-2d4e-4983-875e-c162a9125a7f');
invoiceFiltersMap.put('type', 'invoice');
// Initializing the Request Data to be passed.
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'getTransactionPDF');
reqObj.put('queryParameters', invoiceFiltersMap);
//Required, if Xero Multi-Org is enabled in Breadwinner.
reqObj.put('xeroOrgId', '!14kpg');
// Placing a request to Breadwinner Global API
Map<String, Object> respMap = bread_winner.BreadwinnerXeroAPI.call(reqObj);
System.debug(respMap);Use the response to download the PDF of the transaction. You can achieve this by writing JavaScript to handle the blob content, using the Salesforce Attachment object, or a combination of both approaches.
Sample Usage of the response:
// After making the Breadwinner callout
Map<String, Object> respMap = BreadwinnerXeroAPI.call(reqObj);
if(respMap.get('apiErrors')!=null){
system.debug(respMap.get('apiErrors'));
//write your custom code here
// Breadwinner errors thrown before making a request to Xero. i.e action name incorrect
}
else{ // request successfully sent to Xero
PdfResponse res =(PdfResponse)JSON.deserialize(String.valueOf(respMap.get('responseJSON')),PdfResponse.class);
if(res.statusCode!=NULL && res.statusCode==200){ // Xero returned PDF response
Attachment att = new Attachment();
att.Body = res.pdfResponse;
att.ParentId = '0010p00001Au4vuAAB'; // Salesforce record Id
att.contenttype = 'application/pdf';
att.Name = 'Invoice-pdf-01';
system.debug(att);
Insert att;
}
else{
system.debug(res.errors); // Xero returned errors
}
}
public class PdfResponse{
public Blob pdfResponse;
public Integer statusCode;
public String type;
public String referenceId;
public List<ErrorClass> errors;
}
public class ErrorClass{
public String message;
public String code;
}
In the above code sample, we are using the Attachment object (attach the PDF to any Salesforce record).
You can even use the Document object in place of the Attachment object.