title: PHP cURL: multipart/form-data to REST API
body: <p>I am using the <a href="http://bullhorn.github.io/rest-api-docs/index.html" rel="nofollow noreferrer">Bullhorn REST API</a> to <a href="http://bullhorn.github.io/rest-api-docs/index.html#post-resume-parsetocandidate" rel="nofollow noreferrer">parse resume files</a> (pdf, doc, docx, txt, etc) into JSON data through cURL in PHP. I am able to successfully send the HTTP POST requests and receive a response from the API endpoint.</p>
  
  <p>When I test the API with a sample resume in Postman, I receive the correct response with the data parsed from the resume into JSON. <strong>However</strong>, when I test the API with the same sample resume in PHP using cURL, I receive the correct response, but with <em>no data</em> being parsed from the resume into JSON. </p>
  
  <p>I <em>suspect</em> that the issue is stemming from how I pass file data / form data to the API endpoint in my cURL HTTP POST request. Postman has no problem passing file data to the API endpoint, I just need to figure out how to pass the file data to the API endpoint through PHP cURL.</p>
  
  <p><strong>[Successful] Postman HTTP request:</strong></p>
  
  <pre><code>POST /rest-services/90fdee/resume/parseToCandidate?format=docx HTTP/1.1
  Host: rest34.bullhornstaffing.com
  BhRestToken: 5081ebee-ef0f-4bed-ae8e-41dc50a4e67b
  Cache-Control: no-cache
  Postman-Token: b6420b58-3709-6c76-7bd5-ae8f385009ab
  Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
  
  ------WebKitFormBoundary7MA4YWxkTrZu0gW
  Content-Disposition: form-data; name="file"; filename="SampleResume.pdf"
  Content-Type: application/pdf
  
  
  ------WebKitFormBoundary7MA4YWxkTrZu0gW--
  </code></pre>
  
  <p><strong>[Successful] Postman Response</strong> (not important, just shows that the HTTP request is successful)</p>
  
  <pre><code>{
    "confidenceScore" : "50.00",
    "candidate" : {
      "name" : "Test Johnson",
      "occupation" : "Director Creative Management",
      "companyName" : "Advantage Media",
      "firstName" : "Test",
      "lastName" : "Johnson",
      "email" : "testjohnson@gmail.com",
      "editHistoryValue" : "Test Johnson"
    },
    "candidateEducation" : [ {
      "startDate" : 883674000000,
      "endDate" : 1041440400000,
      "graduationDate" : 1041440400000,
      "school" : "University of Minnesota",
      "degree" : "Bachelor's Degree",
      "major" : "Environmental Science"
    } ],
    "candidateWorkHistory" : [ {
      "startDate" : 1483290000000,
      "endDate" : 1483290000000,
      "companyName" : "Advantage Media",
      "title" : "Director of Creative Management",
      "comments" : "Develop and lead a team of fierce warriors and schematic specialists into the desolate wasteland of business on behalf of our clients. Train employees on how to assist retailer in managing."
    }, {
      "startDate" : 1204390800000,
      "endDate" : 1272729600000,
      "companyName" : "Google",
      "title" : "Janitor",
      "comments" : "Literally just clean stuff and try not to bother the code monkies. They are all cool so it is a good gig."
    } ],
    "skillList" : [ "Eating", "Sleeping", "Programming", "Karate", "Frisbee", "Waiting", "Thinking", "Crying", "Jumping", "Science" ],
    "primarySkills" : [ {
      "id" : 5304,
      "name" : "Accounting"
    }, {
      "id" : 5246,
      "name" : "Business Development"
    }, {
      "id" : 15623,
      "name" : "Consumer"
    }, {
      "id" : 17032,
      "name" : "Distribution"
    }, {
      "id" : 691,
      "name" : "Marketing"
    }, {
      "id" : 6901,
      "name" : "Merchandising"
    }, {
      "id" : 76406,
      "name" : "NEGOTIATIONS"
    }, {
      "id" : 697,
      "name" : "Sales"
    }, {
      "id" : 17872,
      "name" : "STRATEGIC"
    }, {
      "id" : 5283,
      "name" : "Supply Chain"
    } ]
  }
  </code></pre>
  
  <p><strong>[Unsuccessful] PHP cURL code for HTTP request:</strong></p>
  
  <pre><code>$curl = curl_init();
  
  curl_setopt_array($curl, array(
      CURLOPT_RETURNTRANSFER =&gt; true,
      CURLOPT_ENCODING =&gt; "",
      CURLOPT_MAXREDIRS =&gt; 10,
      CURLOPT_TIMEOUT =&gt; 30,
      CURLOPT_CUSTOMREQUEST =&gt; "POST",
      CURLOPT_URL =&gt; "https://rest34.bullhornstaffing.com/rest-services/10ephs/resume/parseToCandidate?format=pdf",
      CURLOPT_HTTP_VERSION =&gt; CURL_HTTP_VERSION_1_1,
      CURLOPT_HTTPHEADER =&gt; array(
          "BhRestToken: 5081ebee-ef0f-4bed-ae8e-41dc50a4e67b",
          "Cache-Control: no-cache",
          "Content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"
      ),
      CURLOPT_POSTFIELDS =&gt; "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"SampleResume.pdf\"\r\nContent-Type: application/pdf\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--",
  ));
  
  
  $response = curl_exec($curl);
  $err = curl_error($curl);
  
  curl_close($curl);
  </code></pre>
  
  <p><strong>[Unsuccessful] PHP cURL Response:</strong></p>
  
  <pre><code>{
    "confidenceScore" : ".00",
    "candidate" : {
    }
  }
  </code></pre>