Fetching PDF documents with API

xtracextrace Member Posts: 4
I've successfully set up an API connection and fetching orders is working well.

I want to fetch/download a PDF document (by using the API) of the order invoice and packing slip and save it on my server. Does anyone know if this is possible and if so, how?


  • gregaricangregarican Member Posts: 510 
    Years ago I employed a library that would convert HTML files to PDF. For an older fax program. Looking around, there are online API's that provide similar functionality. Like this one --> https://pdfcrowd.com/doc/api/. If you can call the URL that renders the order invoice, I'm thinking you could push that into this PDFCrowd API and obtain your PDF. Is this a decent option?
  • xtracextrace Member Posts: 4
    I'd rather just download the (original) documents used by Lightspeed. When browsing the admin and viewing an order there are buttons allowing you to print/download a PDF invoice/packing slip file. Creating my own PDFs (or using a service as PDFCrowd) will force me to extra work, while I think those files should be available in the API. So rather not.
  • gregaricangregarican Member Posts: 510 
    When I look it LS Retail I see a Print Order button. This pops up an HTML page as a print preview. I suppose if your default printer is a PDF printer then it might pop up differently.

    The button appears to be a URL trigger. Your code could substitute the PurchaseId and ShopId I suppose.


  • xtracextrace Member Posts: 4
    In Lightspeed this url is very straightforward:


    This url requires a session cookie login (/admin section), which cannot be done through the API login. And as you can see it is linking to a PDF document.
  • gregaricangregarican Member Posts: 510 
    Oh I see now, you are hitting the eCom API. My apologies, as I usually live in the Retail API. That does present a challenge. I'll defer to LS support, as 99% of my custom development work in Lightspeed involves directly interacting with the Retail API.
  • xtracextrace Member Posts: 4
    No problem, thanks for your time anyways! I hope someone of LS support can help me on this
  • Adrian SamuelAdrian Samuel Moderator, Lightspeed Staff Posts: 625 moderator
    Hey @xtrace, @gregarican had the right idea; as stated by our documentation here: https://developers.lightspeedhq.com/ecom/introduction/resources/ 
    T resource format returned by the an API request is going to be JSON or XML. You'll want to use an existing library supported by your framework to retrieve a PDF document.

    This is essentially how it is done internally, either a custom build/existing library is implemented 

    Adrian Samuel

    Integrations & Solutions Developer - Strategic Solutions

    Lightspeed HQ

Sign In or Register to comment.