0

Hello I am trying to upload file to contentversion via rest api tp salesforce using python. I keep getting an error. Can you please let me know how can I form my request so it adds the boundary string properly following is the method that makes a call to content version in python -

def upload_multipart_to_salesforce(filedata, file_name, instance_url, access_token):

try:
    url = f"{instance_url}/services/data/v52.0/sobjects/Document/"
    headers = {
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'multipart/form-data'
    }

    # Prepare the JSON data

    json_data = {
        "ContentDocumentId":"069Hs00000XWLjAIAX", 
        "ContentLocation":"S",
        "Title":"frompython",
        "PathOnClient":"package1.xml"}

    file_data = ('VersionData', filedata)

    # Prepare the request payload
    payload = {
        'entity_content': (json.dumps(json_data), 'application/json'),
        'VersionData': file_data
    }
    
    response = requests.post(url, headers=headers, form=payload)
except Exception as e:
    # Code that runs if an exception occurs
    print("An error occurred:", e)
return response.json()
1
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Dec 10, 2023 at 6:25

0

You must log in to answer this question.

Browse other questions tagged .