x

Issue with Viewing Invoice PDFs in Square Without Authentication

 

I am implementing a "View Invoice PDF" feature on my webpage, allowing users to access their invoice PDFs via the following Square Sandbox URL:

https://app.squareupsandbox.com/invoices/{invoiceId}/attachments/pdf?inline=true

Currently, this functionality works if I am logged into the Square Dashboard on the same browser. However, when accessed from a different browser or by an unauthenticated user, the following authentication error occurs:

{
  "errors": [
    {
      "category": "AUTHENTICATION_ERROR",
      "code": "UNAUTHORIZED",
      "detail": "This request could not be authorized."
    }
  ]
}

This prevents users from viewing and downloading their invoice PDFs unless they are logged into Square. Is there a way to resolve this issue, or is authentication a strict requirement for accessing invoice attachments?

Best regards,

490 Views
Message 1 of 5
Report
1 Best Answer
Square Community Moderator

Best Answer

Hi @aZticot ! 

 

My recommendation would be to ask this question over in the Square Developer's Forum. Most of the moderators here are not super familiar with coding or APIs. 

 

I think one of my friends @JTPets may have some insight, but not sure. 

 

Sorry i could not be of more assistance, but the developer's forum will probably get you set in the right direction. 

View Best Answer >

443 Views
Message 2 of 5
Report
4 REPLIES 4
Square Community Moderator

Best Answer

Hi @aZticot ! 

 

My recommendation would be to ask this question over in the Square Developer's Forum. Most of the moderators here are not super familiar with coding or APIs. 

 

I think one of my friends @JTPets may have some insight, but not sure. 

 

Sorry i could not be of more assistance, but the developer's forum will probably get you set in the right direction. 

444 Views
Message 2 of 5
Report
Square Champion

I am not a developer and I have very little code skill myself. However it appears that you are using the sandbox which is for testing and not live production.  

 

Change your urls and ensure you use a production api key and url

441 Views
Message 3 of 5
Report
Square Champion

I use AI for a lot of my own Square API issues, here is what the AI says as an additional reply:

The issue here is that Square's invoice PDF URLs are not publicly accessible and require authentication to view. This means:

  1. Authentication Required: The URL only works if the user is logged into Square with an account that has permission to view the invoice.
  2. Sandbox vs. Production: Even in the Square Sandbox environment, authentication is enforced.
  3. No Public Sharing: Unlike some other platforms that generate temporary public links, Square's invoice PDFs are restricted to authorized users.

Possible Solutions:

1. Use Square's API to Fetch the Invoice PDF

  • Instead of relying on a direct URL, use Square’s API to fetch the invoice details and generate a downloadable PDF.
  • You may need to proxy the request through your server if you want to offer the PDF to non-authenticated users.

2. Generate a Temporary Link

  • If public sharing is required, consider using a cloud storage service (AWS S3, Google Drive, etc.) to store and serve the PDFs after fetching them via Square’s API.

3. Embed a Secure Login Mechanism

  • If your users should have access, authenticate them via OAuth to allow them to fetch their invoices.
439 Views
Message 4 of 5
Report
Square Community Moderator

I appreciate you @JTPets ! 

389 Views
Message 5 of 5
Report

Type a product name