title: I want to send file as attachment to an API POST request
body: <p>I am trying to send a file for a candidate in POST request <a href="https://api02.naturalhr.net/api/documentation" rel="nofollow noreferrer">naturalHR API</a>:
  I have tried the same request using <code>POSTMAN</code> and it worked fine. But when i try to integrate the API's <code>POST</code> request using python to attach the file I am getting an error that It <code>cv</code> parameter should be a file(its API error response).</p>
  
  <p><strong>Source Code:</strong></p>
  
  <pre><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)
  </code></pre>
  
  <p>Please dont mark this as a duplicate to a question here which is already been answered because I have tested it by using <strong>files</strong> as request's argument  like:</p>
  
  <pre><code>res = requests.post(api_url, files=files, headers=headers, data=request_data)
  </code></pre>
  
  <p><strong>Edited:</strong>
  The answer which I have tried:</p>
  
  <p><a href="https://stackoverflow.com/questions/24642040/using-python-requests-to-send-file-and-json-in-single-request">Using Python Requests to send file and JSON in single request</a></p>