Invalid multipart payload format - Create import users job - Auth0 Management API

Hi, I need to use the endpoint Create import users job using the Auth0 Management API: Auth0 Management API v2

I did test the endpoint in the Auth0 Management API with my API TOKEN and works inside that.

But, I have problems when I have been to try using cURL, doesn’t work, the response is “Invalid multipart payload format”:

curl --location --request POST 'https://name.auth0.com/api/v2/jobs/users-imports' \
--header 'Authorization: Bearer API_TOKEN' \
--header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
--form 'users=@/home/sebaxtian/Downloads/tmpfile_bulk' \
--form 'connection_id=con_123likethis456'

I did the test, using Postman and in this case, it works:

I need to Create import users job from Python Code, like this:

import requests
url = "https://name.auth0.com/api/v2/jobs/users-imports"
payload = {'connection_id': 'con_HwCa2wIHpzgGff71'}
files = [
  ('users', open('/home/sebaxtian/Downloads/tmpfile_bulk','rb'))
]
headers = {
  'Authorization': 'Bearer API_TOKEN',
  'Content-Type': 'multipart/form-data; boundary=---011000010111000001101001'
}
response = requests.request("POST", url, headers=headers, data = payload, files = files)
print(response.text.encode('utf8'))

But, doesn’t work, the response is: “Invalid multipart payload format”

Please, anybody can give me a hand?, I need help with these issues, really I need to Create import users job from Python Code.

The problem was solved:

You need only remove the boundary attribute in headers, for example with cURL this is now working fine:

curl --request POST \
  --url 'https://cleanpass-dev.auth0.com/api/v2/jobs/users-imports' \
  --header 'authorization: Bearer API_TOKEN' \
  --header 'content-type: multipart/form-data' \
  --form 'users=@/home/sebaxtian/Downloads/tmpfile_bulk' \
  --form 'connection_id=con_123likethis456'

Now the bellow Python code it’s working fine:

import requests
url = "https://name.auth0.com/api/v2/jobs/users-imports"
payload = {'connection_id': 'con_123likethis456'}
files = [
  ('users', open('/home/sebaxtian/Downloads/tmpfile_bulk','rb'))
]
headers = {
  'Authorization': 'Bearer API_TOKEN'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text.encode('utf8'))

Example Response:
{"type":"users_import","status":"pending","connection_id":"con_123likethis456","connection":"Name-Database-Dev","created_at":"2020-06-29T16:29:43.092Z","id":"job_1234YWcGhypZsYzR"}

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