I am trying to send a file for a candidate in POST request naturalHR API:
I have tried the same request using POSTMAN
and it worked fine. But when i try to integrate the API's POST
request using python to attach the file I am getting an error that It cv
parameter should be a file(its API error response).
Source Code:
from pprint import pprint
import json
import requests
import urllib.request
headers = {
'accept': 'application/json',
'Authorization': api_key,
'Host': 'api02.naturalhr.net',
'Referer': 'https://api02.naturalhr.net/api/documentation',
'Content-type': 'multipart/form-data',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36'
}
payLoad = dict()
payLoad["firstname"] = json_of_vals['firstname']
payLoad["surname"] = json_of_vals['surname']
payLoad["email"] = json_of_vals['email']
payLoad["cv"] = "Path/To/PDF_File"
files = {'file': "outfilename.pdf"}
api_url = "https://api02.naturalhr.net/api/v1/candidate"
res = requests.post(api_url, files=files, headers=headers, data=request_data)
print(res.content)
Please dont mark this as a duplicate to a question here which is already been answered because I have tested it by using files as request's argument like:
res = requests.post(api_url, files=files, headers=headers, data=request_data)
Edited: The answer which I have tried:
Using Python Requests to send file and JSON in single request