[Python] Square API for invoice attachments 'Received multiple request parts. Please only...

Discussão em 'Python' iniciado por Stack, Abril 30, 2025.

  1. Stack

    Stack Membro Participativo

    The new square api versions 42+ have breaking changes. Im trying to upgrade to ver v42, and I am testing in a local dev environment.

    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.'}]}

    when I try to upload an approx ~800 byte jpeg [very grainy] in the development sandbox for Square Invoice API using the following code:

    pdf_filepath = 'local/path/to/file.jpg'
    idem_key = 'some-unique_key_like_square_invoice_id'
    f_stream = open(pdf_filepath, "rb")
    try:
    # I have tried using a stream as well, still the same error
    invoice_pdf = SQUARE_CLIENT.invoices.create_invoice_attachment(
    invoice_id=square_original_invoice.id,
    # this also does not work
    # image_file=f_stream,
    image_file=pdf_filepath,
    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 online 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?

    Related Docs https://developer.squareup.com/docs/invoices-api/attachments

    Continue reading...

Compartilhe esta Página