title: Create a file with content on OneDrive for Business with Files REST API
body: <p>I've been trying to write an app that uploads files to a OneDrive for Business account through the Files REST API.</p>
  
  <p>I've successfully been able to use do this by using with the following method</p>
  
  <ol>
  <li>Creating an empty file in the root directory.</li>
  <li>Uploading the file contents in a second API call.</li>
  <li>Updating the file properties to move it to the correct subdirectory in a third API call.</li>
  </ol>
  
  <p>However, according to the documentation (<a href="https://msdn.microsoft.com/office/office365/APi/files-rest-operations#FileoperationsUploadcontentforafileREST" rel="nofollow noreferrer">https://msdn.microsoft.com/office/office365/APi/files-rest-operations#FileoperationsUploadcontentforafileREST</a>) I should be able to do this in a single API call.</p>
  
  <p>Unfortunately that endpoint's documentation isn't clear on what the payload should be and doesn't have any examples (haven't found any online either).</p>
  
  <p>I've been taking guesses on the headers/formats, but they look similar to</p>
  
  <pre><code>POST https://{tentant}-my.sharepoint.com/_api/v1.0/me/files/{parent-id}/children/add
  Content-Type: multipart/related; boundary=my_boundary
  
  --my_boundary
  Content-Type: application/json
  
  { path : 'my_doc.txt', nameConflict : 'abort', type : 'File' }
  --my_boundary
  Content-Type: application/octet-stream
  
  {file stream}
  --my_boundary--
  </code></pre>
  
  <p>Every combination I've tried so far returns this error:</p>
  
  <pre><code>  {
      "code"=&gt;"InvalidArgument",
      "message"=&gt;"The argument is invalid, missing, or has an incorrect format"
    }
  </code></pre>
  
  <p>Where am I going wrong?</p>