title: Getting a Count of Contacts from Outlook Office REST API - Javascript
body: <p>I'm having difficulty distinguishing between Microsoft's absurd amount of conflicting API documentations: outlook.office.com, outlook.office365.com, microsoft graph, Azure, and so on</p>
  
  <p>I've successfully authenticated and pulled contacts, but I can't seem to get a count to know when I should stop pagination. </p>
  
  <p>I've been using:</p>
  
  <pre><code>Access Token url: 
      https://login.microsoftonline.com/common/oauth2/v2.0/token;
  Successful Contact url: 
      https://outlook.office.com/api/v2.0/me/contacts;
  </code></pre>
  
  <p>Their <a href="https://msdn.microsoft.com/en-us/office/office365/api/complex-types-for-mail-contacts-calendar#contact" rel="nofollow">REST API Resource</a> says I should be able to simply make a call to <code>https://outlook.office.com/api/v2.0/me/contacts/$count</code> but this keeps returning a plaintext MIME type with body <code>-1</code>.</p>
  
  <p>If anyone has struggled with this before or knows what's going on, I'd appreciate a point in the right direction - and hopefully some easy points for you!</p>
  
  <hr/>
  
  <p><strong>EDIT</strong>: Thanks to Jason below for his helpful support. Using the sandbox I was able to reproduce the issue with the following:</p>
  
  <p>Logged in to my account -> Received Access Tokens -> Made a GET call to <code>https://outlook.office.com/api/v2.0/me/contacts/$count</code></p>
  
  <p><strong>Request Headers:</strong> </p>
  
  <pre><code>GET https://outlook.office.com/api/v2.0/me/contacts/$count HTTP/1.1
  Accept: text/*, application/xml, application/json; odata.metadata=none
  User-Agent: PlayGroundAgent/1.0
  Authorization: Bearer [standard-access-token]
  client-request-id: 8f605[client-id-obscured-for-security]7289
  X-AnchorMailbox: [email-address-removed-for-security on stackOverflow]
  </code></pre>
  
  <p><strong>Response</strong></p>
  
  <pre><code>HTTP/1.1 200 OK
  Transfer-Encoding: chunked
  request-id: de95eaa8-95a7-40bb-b0f9-ced7270f0433
  X-CalculatedBETarget: SN1PR05MB1998.namprd05.prod.outlook.com
  X-BackEndHttpStatus: 200
  OData-Version: 4.0
  X-DiagInfo: SN1PR05MB1998
  X-BEServer: SN1PR05MB1998
  X-FEServer: SN1PR0501CA0035
  X-MSEdge-Ref: Ref A: 657E0491C29D46978D8DD3B01B9F93A3 Ref B: DDDD64A109F4E842A8213F038BFDD5FA Ref C: Fri Aug 19 09:20:05 2016 PST
  Cache-Control: private
  Date: Fri, 19 Aug 2016 16:20:05 GMT
  Set-Cookie: exchangecookie=6ca5fc4df96e458e8b879de61aa574ef; expires=Sat, 19-Aug-2017 16:20:05 GMT; path=/; HttpOnly
  Server: Microsoft-IIS/8.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  
  -1
  </code></pre>
  
  <hr/>
  
  <p><strong>2nd Edit</strong>: It looks like <code>https://outlook.office.com/api/v2.0/me/contacts?$count=true</code> returns <code>@odata.count": -1</code> as well, even as it returns valid array of contacts.</p>
  
  <hr/>
  
  <p><strong>3rd Edit: Working version</strong> (Same method was used as the errors above)
  Url: <a href="https://outlook.office.com/api/v2.0/me/contacts/" rel="nofollow">https://outlook.office.com/api/v2.0/me/contacts/</a>$count</p>
  
  <p><strong>Request Headers:</strong> </p>
  
  <pre><code>GET https://outlook.office.com/api/v2.0/me/contacts/$count HTTP/1.1
  Accept: text/*, application/xml, application/json; odata.metadata=none
  User-Agent: PlayGroundAgent/1.0
  Authorization: Bearer [access-token]
  client-request-id: a7954db3-[client-id]-7a6e2e74dd9c
  X-AnchorMailbox: [same-email-as-above]
  </code></pre>
  
  <p><strong>Response</strong>:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Transfer-Encoding: chunked
  request-id: 8c5db16b-3023-4968-9bdc-3d5ecac12ecb
  X-CalculatedBETarget: SN1PR05MB1998.namprd05.prod.outlook.com
  X-BackEndHttpStatus: 200
  OData-Version: 4.0
  X-DiagInfo: SN1PR05MB1998
  X-BEServer: SN1PR05MB1998
  X-FEServer: SN1PR0501CA0019
  X-MSEdge-Ref: Ref A: 0574E46DB720491FBCEF23B73428F191 Ref B: FA4529229719F069B9D019E4D53E9200 Ref C: Fri Aug 19 09:42:55 2016 PST
  Cache-Control: private
  Date: Fri, 19 Aug 2016 16:42:55 GMT
  Set-Cookie: exchangecookie=63a1de916a4c48be88569f05ce0361a7; expires=Sat, 19-Aug-2017 16:42:55 GMT; path=/; HttpOnly
  Server: Microsoft-IIS/8.5
  X-AspNet-Version: 4.0.30319
  X-Powered-By: ASP.NET
  
  29
  </code></pre>
  
  <p>Hope these help!</p>