I keep getting the following error:
*** square.core.api_error.ApiError: status_code: 400, body: {'errors': [{'category': 'INVALID_REQUEST_ERROR', 'code': 'INVALID_CONTENT_TYPE', 'detail': 'Received multiple request parts. Please only supply zero or one `parts` of type application/json.'}]}
It does not make sense that the API response focuses on an “application/JSON” type request when the parameters to the API method are supplied are a file path (stream or text path) and request dict as the docs require.
when I try to upload an approx ~800 byte jpeg [very grainy] in the development sandbox for Square Invoice API using the following code:
try:
# I have tried using a stream as well, still the same error
# f_stream = open(pdf_filepath, "rb")
invoice_pdf = SQUARE_CLIENT.invoices.create_invoice_attachment(
invoice_id=self.square_original_invoice.id,
# image_file=f_stream, <- this also does not work
# file=pdf_filepath, <- also gives error InvoicesClient.create_invoice_attachment() got an unexpected keyword argument 'file'
image_file=pdf_filepath,
# pdf_filepath = 'local/path/to/file.jpg'
request={
"description": f"Invoice-{pdf_filepath}",
"idempotency_key": idem_key,
},
)
except ApiError as e:
print(f"ERROR _attach_pdf_to_vendor_payment with errors {e}")
In the sandbox API, I get the 400 Response error:
// cache-control: no-cache
// content-type: application/json
// date: Wed, 30 Apr 2025 13:35:06 GMT
// square-version: 2025-04-16
{
"errors": [
{
"code": "BAD_REQUEST",
"detail": "Total size of all attachments exceeds Sandbox limit: 1000 bytes",
"category": "INVALID_REQUEST_ERROR"
}
]
}
This worked fine in the old pre 42 API, with minor syntax change, and I know the limit is now imposed to have a 1000 byte limit for the attachment, but why can’t I upload attachments in the sandbox now?
Stack overflow link : python - Square API for invoice attachments 'Received multiple request parts. Please only supply zero or one `parts` of type application/json.' - Stack Overflow
13 posts - 3 participants