it will show file not found and no url in data when i download excel .
please correct below code
URL = f’https://kf.kobotoolbox.org/api/v2/assets/{project_id}/data/bulk/’
PARAMS = {
‘format’: ‘json’
}
HEADERS = {
‘Authorization’: f’Token {TOKEN}’
}
file_path = ‘signed_user_agreement.pdf’ # or path to the image file
with open(file_path, ‘rb’) as file:
# Create the payload without the file name
payload = {
'submission_ids': ['395241386'],
'data': {
‘End_user_agreement_file’: ‘signed_user_agreement.pdf’
},
‘data_type’: ‘media’,
‘confirm’: ‘true’
}
# Create the files dictionary for the file upload
files = {
'signed_user_agreement.pdf': file }
# Send the request
res = requests.patch(
url=URL,
data={'payload': json.dumps(payload)}, # Send other form data directly
files=files, # Include the file in the request
params=PARAMS,
headers=HEADERS
)
# Print response status code and text
print(res.status_code)
print(res.text)