Website logo
Product Overview
NetSuite
Payments
QuickBooks
Xero
Navigate through spaces
⌘K
Getting Started
Guided Wizard
Guided Wizard Settings
Custom Guided Wizard
Button URL Structure
Button URL Generator
Support
Global API
API Overview
Request
Response
Code Examples
Advanced Topics
Batch Invoicing
Technical Resources
Breadwinner Setup
Requirements
ERD / Object Structure
Getting Help
Version History
Docs powered by Archbee
Global API
Request

Get PDF Response

2min

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
Request
Response
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. Either we can write some javascript to download the blob content or use the Salesforce Attachment object or a combination of both.

Sample Usage of the response:

Apex
// 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.

Updated 03 Mar 2023
Did this page help you?
PREVIOUS
Online Invoice
NEXT
Item
Docs powered by Archbee
Docs powered by Archbee