[Python] Convert Python Request call to PHP (cURL)

Discussão em 'Python' iniciado por Stack, Janeiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am pulling my hair out :)

    THe company I am using has a API I need to use but only gives an example to me in Python.

    Can someone help me write it in PHP? I have tried several times but no luck. I think the problem is in the file sending.

    Here is the Python code:

    import requests
    import json

    def send_excel_catalog_import(fname, auth_token, report_recipient_email):

    api_url = f"https://www.etailpet.com/COMPANY/api/v1/catalog-update/"

    payload = {"email": report_recipient_email}

    files = [
    ("product_import", open(fname, "rb"))
    ]

    headers = {"Authorization": f"Bearer {auth_token}"}

    response = requests.request(
    "POST", api_url, headers=headers, data=payload, files=files
    )

    results_str = response.content.decode("utf8")
    return response.status_code, json.loads(results_str)

    if __name__ == "__main__":

    fname = "product_import.xlsx"
    send_excel_catalog_import(fname)

    Continue reading...

Compartilhe esta Página