Office 365 REST API /$count filter giving wrong data - api

I'm trying to get count of records for different objects. The response of /$count filtered APIs is inconsistently giving wrong response.
I am referring this documentation link for usage instructions.
Request URL: GET https://outlook.office.com/api/v2.0/me/Events/$count
Response: -1
To verify if the above mentioned response is legitimate, I tried to get all events with a skip filter to identify the actual number of records present.
After a certain attempts following request URL gave me final count:
Request URL: GET https://outlook.office.com/api/v2.0/me/events/?$skip=159
Response:
{
"#odata.context": "https://outlook.office.com/api/v2.0/$metadata#Me/Events",
"value": [
{
"Id": "AAMkADMzYzIxNTBjLWUyMWUtNDgzYi04NTEwLTc5YTkzMWI5MmE4MgBGAAAAAABjOnbtK9ZkTIjwInd5bfYcBwDe_ScfFfAUQaKHRwnzV1lBAAAAAAENAADe_ScfFfAUQaKHRwnzV1lBAACs2ojfAAA=",
"CreatedDateTime": "2016-11-28T11:09:03.8359488Z",
"LastModifiedDateTime": "2017-02-21T08:04:48.8262751Z"
}
]
}
This implies that after skipping 159 records, I've 160th record present in the authenticated account but $count filtered API doesn't give me a valid response.
I tried testing this scenario with two different accounts where I noticed this anomaly for /message API as well. The HTTP GET call to messages/$count gives me 1563 whereas after trying with skip filter I found the total count to be 1396
I want to know if $count returns a legitimate response? If yes then explain this anomaly If no then is there any pattern where we should expect response to inconsistent?

To get a count of the number of events, you need to specify start time and end time. Here is what I use:
https://outlook.office.com/api/v2.0/me/calendarview/$count?startDateTime=2017-05-01T00:00:00Z&endDateTime=2017-05-31T23:59:59Z
If you don't specify the dates, you will get 400 with the following error message:
{"error":{"code":"ErrorInvalidParameter","message":"This request requires a time window specified by the query string parameters StartDateTime and EndDateTime."}}

Related

Http status code when data not found in Database

I'm trying to understand which Http Status Code to use in the following use case
The user tries to do a GET on an endpoint with an input ID.
The requested data is not available in the database.
Should the service send back:
404 - Not Found
As the data is NOT FOUND in the database
400 - Bad Request
As the data in the input request is not valid or present in the db
200 - OK with null response
200 - OK with an error message
In this case we can use a standard error message, with a contract that spans across all the 200 OK responses (like below).
BaseResponse {
Errors [{
Message: "Data Not Found"
}],
Response: null
}
Which is the right (or standard) approach to follow?
Thanks in advance.
Which is the right (or standard) approach to follow?
If you are following the REST API Architecture, you should follow these guidelines:
400 The request could not be understood by the server due to incorrect syntax. The client SHOULD NOT repeat the request without modifications.
It means that you received a bad request data, like an ID in alphanumeric format when you want only numeric IDs. Typically it refers to bad input formats or security checks (like an input array with a maxLength)
404 The server can not find the requested resource.
The ID format is valid and you can't find the resource in the data source.
If you don't follow any standard architecture, you should define how you want to manage these cases and share your thought with the team and customers.
In many legacy applications, an HTTP status 200 with errors field is very common since very-old clients were not so good to manage errors.

HTTP status code response when there is not matched data with DB

I am building an API about email auth code.
Its process is simple.
input random code (client browser)
request with input code. (client browser)
receive the request (server)
scan the code from DB (server)
there is no code matched (server)
return a response with status code.
There are many status code, (2xx, 4xx, 5xx);
but I don't know which status code number is the most proper for this case.
It depends on the semantics you want to give your request. E.g.:
The API should search for items matching the query and return a list of results, like GET /codes?q=4ba69g. Think a "search page". In this case, an empty result [] is a perfectly valid result; nothing was wrong with the query, it just didn't return any matches. That's a 200 OK, or maybe a 204 No Content if you want to omit the empty response body entirely.
The code is treated like a resource, e.g. GET /codes/4ba69g. In this case a missing code would result in a 404 Not Found.
It's an action you want to perform which may fail, e.g. POST /login. If the user supplied the wrong credentials/code and hence the action cannot complete, that's a client-side error and therefore a 400 Bad Request.

Can BigQuery report mismatched the schema field?

When I upsert a row that mismatches schema I get a PartialFailureError along with a message, e.g.:
[ { errors:
[ { message: 'Repeated record added outside of an array.',
reason: 'invalid' } ],
...
]
However for large rows this isn't sufficient, because I have no idea which field is the one creating the error. The bq command does report the malformed field.
Is there either a way to configure or access name of the offending field, or can this be added to the API endpoint?
Please see this Github Issue: https://github.com/googleapis/nodejs-bigquery/issues/70 . Apparently node.js client library is not getting the location field from the API so it's not able to return it to the caller.
Workaround that worked for me: I copied the JSON payload to my Postman client and manually sent a request to REST API (let me know if you need more details of how to do it).

Twitter API followers/ids - All Followers Returned but next_cursor is still present

I have been working with the Twitter API [followers/ids] for a few of our accounts but recent got stuck with a confusing state.
Usually twitter returns a next_cursor when there are still some records remaining in next page(s). It works fine with iteration but recently when I tried to request followers/ids for one of our accounts which doesn't have a lot of followers (just over 4200) and all can be returned in single request. Even though, the API returns all the followers in a single request but strangely the next_cursor is still present.
So when I try to make another (2nd) request with that cursor, only one record is returned which is not present in the first set of records.
What should I consider that how much followers the user actually have?
Total Followers: 4224
1st Request: 4224 [next_cursor: present]
2nd Request with cursor: 1
This is creating confusion as it is 4224 or 4225?
Attaching a screenshot

What value actually need to provide {item-path} in view.delta OneDrive for Business API

I am using /drive/root:/{item-path}:/view.delta for getting the changes of a file in OneDrive for Business in root folder. I have tried with the path like /drive/root:/Files/filename:/view.delta but the response is resource not found. Can someone please explain what exactly this value ?
The link I am following is below.
more details
The error would suggest that /Files/filename does not exist, however even if it did you'd run into another limitation of how view.delta currently works with OneDrive for Business. To make a long story short, it's limited to only working on the root of the drive, i.e. /drive/root/view.delta. Using this path you'll get back changes for ALL items within the drive, not just the one that you're interested in.
Given that you're trying to detect changes in a single file you may want to consider a standard metadata request with an If-None-Match header that contains the ETag of the last state your application saw.
For example, you'd first make a request without any additional headers to get the initial state:
Request:
GET /_api/v2.0/drive/root:/File/filename
Response:
200 OK
{
...
"name": "filename",
"etag": "\"aasdfasdf\"",
"modifiedDateTime": "2016-01-01T00:00:00Z",
...
}
At some point in the future you'd then make a call using the etag value in the If-None-Match header:
Request:
GET /_api/v2.0/drive/root:/File/filename
If-None-Match: "aasdfasdf"
Response:
304 Not Modified
If the file has actually changed you'd get back the new response.
Request:
GET /_api/v2.0/drive/root:/File/filename
If-None-Match: "aasdfasdf"
Response:
200 OK
{
...
"name": "filename",
"etag": "\"poihklhjl\"",
"modifiedDateTime": "2016-04-19T00:00:00Z",
...
}