title: Download file from SharePoint
body: <p>I'm using the REST APIs of SharePoint to query the files hosted inside a corporate user's Office 365 SharePoint site.</p>
  
  <p>I have used OAuth to authenticate the user and authorize the the app, as described here: <a href="http://msdn.microsoft.com/en-us/library/azure/dn645542.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/azure/dn645542.aspx</a></p>
  
  <p>I am able to successfully query the API with a GET request on:
  <a href="https://XXXXXXX.sharepoint.com/sites/xxxxx/xxxxx/myfoldername/_api/files" rel="nofollow">https://XXXXXXX.sharepoint.com/sites/xxxxx/xxxxx/myfoldername/_api/files</a>
  (the request as the Authorization header set to 'Bearer ', as you'd expect.)</p>
  
  <p>The above query gives me the following JSON result:</p>
  
  <pre><code>{
      "odata.metadata" = "https://xxxxxxxxx.sharepoint.com/sites/xxxxxxxxx/xxxxxxxxx/myfoldername/_api/$metadata#SP.ApiData.Files";
      value =     ( 
                  {
              CreatedBy =             {
                  Id = 1;
                  Name = “Test”;
                  Puid = xxxxx;
              };
              ETag = “\”{hsdglksjfldkasnfldasknk},4\””;
              Id = JKLBbiuuu908yYHhh89YBn9n9ynynYUN;
              LastModifiedBy =             {
                  Id = 1;
                  Name = “XXXXX”;
                  Puid = XXXXXXXXXXX;
              };
              Name = "videofile.wmv";
              Size = 56492358;
              TimeCreated = "2013-09-23T05:16:44Z";
              TimeLastModified = "2013-09-23T05:28:42Z";
              Url = "https://xxxxxxxxx.sharepoint.com/sites/xxxxxxxxx/xxxxxxxxx/myfoldername/Shared Documents/videofile.wmv";
              "odata.editLink" = "Web/Lists(guid’9568472598-2c28-489BF2-a1ae-kfjdasfkjb)/files(‘jkbvasdjfbakfndasnMNBBAMnsaldfan)”;
              "odata.id" = "https://xxxxxxxxx.sharepoint.com/sites/xxxxxxxxx/xxxxxxxxx/myfoldername/_api/Web/Lists(guid’987795-gfkjhghs-ty42398yhfo’)/files('jkbvasdjfbakfndasnMNBBAMnsaldfan')";
              "odata.type" = "MS.FileServices.File";
          })
  }
  </code></pre>
  
  <p>(Bear in mind the above is not actually JSON, but text output from a JSON parser)</p>
  
  <p>In the result above, I get an array of files inside the <code>value</code> part.  I have cut this array down to one item for illustrative purposes.</p>
  
  <p>You'll see each item represents a file's meta data.   There's a property called <code>Url</code>; I then use this to attempt to download the file.  I create an HTTP request, append the Authorization header with <code>Bearer &lt;access_token&gt;</code>, however, the response is always an <code>HTTP 401 UNAUTHORIZED</code>.</p>
  
  <p>Please note: the software I'm writing is actually in Objective-C using AFNetworking 2's <code>AFHTTPRequestOperationManager</code>.</p>
  
  <p>Does anyone know how I can actually download the file?  I have seen references to some property called 'contentUrl' in the docs, but this property is not supplied.</p>
  
  <p>thanks
  Kris</p>