Load-accounts triggering an aggregation with a csv

Below is my Python logic. I’m receiving a 500 error.

I don’t see a great example on how to compose the multipart/form-data. Any assistance would be appreciated.

def update_accounts(tenant, token, source_id, file_path):
    base_url = f"https://{tenant}.api.identitynow-demo.com/beta/sources/{source_id}/load-accounts"

    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "multipart/form-data",
    }

    files = {'file': ('example.csv', open(file_path, 'rb'), 'text/csv')}
    response = requests.request('POST', base_url, headers=headers, files=files)

    if response.status_code == 200:
        return "Success: Accounts updated."
    else:
        return f"Error: {response.status_code} - {response.text} - Updating Accounts"

I was able to Update the source accounts with the csv.

Below is the python code that is working for me.

def update_accounts(tenant, token, source_id, file_path):
    base_url = f"https://{tenant}.api.identitynow-demo.com/beta/sources/{source_id}/load-accounts"

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

    # Open the CSV file in binary mode
    file = open("accounts.csv", "rb")

    try:
        # Prepare the files dictionary
        files = {
            "file": ("accounts.csv", file, "text/csv")  # Include filename and content-type
        }


        response = requests.request('POST', base_url, headers=headers, files=files)

        if response.status_code == 200:
            return "Success: Accounts updated."
        else:
            return f"Error: {response.status_code} - {response.text} - Updating Accounts"

    finally:
        # Ensure the file is closed after the request
        file.close()

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.