Odata query for outlook rest api - json

How to use search and filter in the same query?
String url = "https://outlook.office.com/api/v2.0/me/messages?$filter=ReceivedDateTime ge 2016-02-22&$select=Subject,From,Body,ReceivedDateTime&$search=\"subject:(Chris Brown OR Michael Jackson)\"";
I need to find all mails with Subject having either "Chris Brown" or "Michael Jackson" and mail received date after 22nd Feb, 2016. Also it should have Subject, From, Body, ReceivedDateTime in the REST response.
Could anyone please help?
FYI - I am getting output if it has either filter or search. But when given together, I am getting a "Bad Request" error.

Right now this is not supported. From Use OData query parameters:
You cannot use $filter or $orderby in a search request.
So, the only way to do this is to perform a search via a query, and then filter on the client; or vice versa.
Update
In this particular case, since subject is filtrable and supposedly you only need an exact subject match (and not 'contains' for example), you can use something along the lines of:
https://outlook.office.com/api/v2.0/me/messages?$filter=(ReceivedDateTime ge 2016-02-22) and ((subject eq 'Chris Brown') or (subject eq 'Michael Jackson'))

To answer the original question: yes it is possible. #roman-pletnev correctly pointed out that you cannot use $filter or $orderby in a $search request. However, you can achieve the desired result using just $search.
$search="
(subject:(Chris Brown) OR subject:(Michael Jackson))
AND (received:02/22/2016..10/21/2016)
"
Note that extra linebreaks have been included for readability.
Also note that the received parameter seems to only work with a single date, or a specific range. I.e. you cannot request "everything after 02/22/2016". Instead you have to input today's date (or a future date?) as the end of the range.
received:<date>
received:02/22/2016
received:<start>..<end>
received:02/22/2016..10/21/2016
I'm not 100% sure about the date format. I don't know if it's determined by your account's locale or if it's always MM/DD/YYYY.
Other variations seem to work as well. However, the documentation for this is very bad and most of the documented syntax for "received" doesn't seem to work. I've filed a support ticket with Microsoft regarding this.
Some other documented syntax does work, for example received:today
Some documented syntax does not work, for example received:October
References:
https://support.office.com/en-us/article/Learn-to-narrow-your-search-criteria-for-better-searches-in-Outlook-d824d1e9-a255-4c8a-8553-276fb895a8da
https://support.office.com/en-us/article/Search-Mail-and-People-in-Outlook-on-the-web-for-business-88108edf-028e-4306-b87e-7400bbb40aa7
https://msonlinehelpdesk.zendesk.com/hc/en-us/articles/200561417-Learn-how-to-fine-tune-email-search-results-in-Outlook-and-Outlook-Web-App-OWA-

Related

SSRS REST API - I Want to get all CatalogItems where Type = Report

I'm using Postman to test a GET on my SSRS database. The GET is "http://server/reports/api/v2.0/CatalogItems". This works and gives me lots of information. One of the values is "Type": which has values such a "Folder" and "Report". I would like to get only the Reports. I can get a specific report using "http://server/reports/api/v2.0/CatalogItems?$filter=Name eq 'ReportXYZ'". But if I use "?$filter=Type eq 'Report'" I get the error "The query specified in the URI is not valid. A binary operator with incompatible types was detected. Found operand types 'Model.CatalogItemType' and 'Edm.String' for operator kind 'Equal'."
Any ideas how to do this? Thanks!
FINALLY found the answer! "?$filter=Type eq Model.CatalogItemType'Report'". I don't know why this isn't documented better on the Swagger site or one of Microsoft's pages.
Type is a enum, not a string. So for any enum's this should work.

API Query Syntax - JSON object could not be decoded

This relates to the Patentsview.org API.
http://www.patentsview.org/api/uspc.html#field_list
I would like to modify my current query to limit itself to one or more USPC IDs (US patent classification) I am using id=348 for my test case.
Here is a query I have that works:
PATENTS_API_URL_TEMPLATE = 'http://www.patentsview.org/api/patents/query?q={%22_text_any%22:{%22patent_abstract%22:%22term_placeholder%22}}&f=[%22patent_number%22,%22patent_date%22,%22inventor_last_name%22,%22patent_abstract%22]'
The above query searches for the term_placeholder anywhere in the text and returns the patent number, data, inventors last name, and abstract.
I don't care about the date and name. I only care about the patent number and abstract. But I also want to limit it to one or more patent classes.
I tried the following:
PATENTS_API_URL_TEMPLATE = 'http://www.patentsview.org/api/uspc_mainclasses/query?q={%22_and%22:[{%22_text_any%22:{%22patent_abstract%22:%22term_placeholder%22}},{%22uspc_mainclass_id%22:%22348%22}}]}&f=[%22patent_number%22,%22patent_abstract%22]'
The error I get is ValueError: No JSON object could be decoded.
I was using the following example provided by Patentsview:
http://www.patentsview.org/api/uspc_mainclasses/query?q={"_and":[{"_contains":{"assignee_organization":"Census"}},{"_gte":{"patent_date":"2000-01-01"}},{"_lte":{"patent_date":"2010-12-31"}},{"_contains":{"uspc_mainclass_title":"Electricity"}}]}&f=["inventor_id","inventor_first_name","inventor_last_name"]
I replaced the double quotes with %22, switched from api/patents to api/uspc_mainclasses, removed the name and date fields, and otherwise tried to follow the example.
What am I doing wrong? Thanks!
You just have an extra } after the 348". Without it the api returns the json you are looking for
[https://api.patentsview.org/uspc_mainclasses/query?q={"_and":\[{"_text_any":{"patent_abstract":"term_placeholder"}},{"uspc_mainclass_id":"348"}\]}&f=\["patent_number","patent_abstract"\]][1]
You can search multiple classes by changing the uspc_mainclass_id to an array
[https://api.patentsview.org/uspc_mainclasses/query?q={"_and":\[{"_text_any":{"patent_abstract":"term_placeholder"}},{"uspc_mainclass_id":\["348","343"\]}\]}&f=\["patent_number","patent_abstract"\]][2]
Note that the uspc classifications stopped being used by the patent office in June 2015. Your query won't return results more recent that than. You'll need to use the cpc classification fields like cpc_group_id if you want to do classification searches that return more recent results.
[1]: https://api.patentsview.org/uspc_mainclasses/query?q=%7B%22_and%22:[%7B%22_text_any%22:%7B%22patent_abstract%22:%22term_placeholder%22%7D%7D,%7B%22uspc_mainclass_id%22:%22348%22%7D]%7D&f=[%22patent_number%22,%22patent_abstract%22]
[2]: https://api.patentsview.org/uspc_mainclasses/query?q=%7B%22_and%22:[%7B%22_text_any%22:%7B%22patent_abstract%22:%22term_placeholder%22%7D%7D,%7B%22uspc_mainclass_id%22:[%22348%22,%22343%22]%7D]%7D&f=[%22patent_number%22,%22patent_abstract%22]

MailChimp Interested Value in "Group" always false after "subscribing"

I send over proper json formatted code, according to v2 api docs:
lists/subscribe.json
"GROUPINGS":[{"id":removed_id,"name":"grouping_name","groups":["group_name"]}]
I get back information about a member... It does not say they are interested in that group name..
lists/member-info.json
"GROUPINGS":[{"id":removed_id,"name":"grouping_name","form_field":"hidden","groups":
[{"name":"group_name","interested":false},{"name":"other_group_name","interested":false},
{"name":"other_group_name2","interested":false},{"name":"other_group_name3","interested":false}]}]
I do not understand how I can get these users to show up as "subscribed" to a group within my grouping. I have been trying for nearly 5 hours now. I have tried:
making sure the groups: value is an [] array.
trying out making that value a string (which surprisingly did not throw errors)
capitalizing "GROUPINGS" when sending it in merge_vars
not capitalizing "groupings" when sending in merge_vars
using the lists/update-member.json method to update these groups
using the name of my interest group instead of grouping in the grouping array.
using the option replace_interests on both true and false
In conclusion,
I had to email mailchimp a support ticket. Without changing my code at all - it works this morning. Interestingly enough, mailchimp was experiencing many issues yesterday with servers being down and alleged email hackings.
To be clear about which version of my code worked - following the API exactly for v2.
It was an error on mailchimp's end.
{
"id":"MY LIST ID",
"email":{
"email":"THE EMAIL TO SUBSCRIBE"
},
"merge_vars":{
"GROUPINGS":[
{
"id":THE GROUPING ID,
"groups":[
"THE NAME OF MY GROUP"
]
}
]
},
"double_optin":false,
"replace_interests":true,
"apikey":"MY API KEY"
}
Also, in case you are curious, replace_interests is true when the groups you send are supposed to replace existing groups the subscriber is interested in. False indicates that the groups you pass should be added to the interest groups.
If you are updating a member (method: lists/update-member), it may be best to set replace_interests to false just to make sure it does not overwrite your existing interest groups (possibly with blank groups). The default value for it is true, so this could be another place prone to error.

Gerrit REST API: cannot use _sortkey to resume a query

I'm using Gerrit REST API to query all changes whose status is "merged". My query is
https://android-review.googlesource.com/changes/?q=status:merged&n=2
where "n=2" limits the size of query results to 2. So I got a JSON object like:
Of course there are more results. According to the REST document:
If the n query parameter is supplied and additional changes exist that match the query beyond the end, the last change object has a _more_changes: true JSON field set. Callers can resume a query with the N query parameter, supplying the last change’s _sortkey field as the value.
So I add the query parameter N with the _sortkey of the last change 100309. The new query is:
https://android-review.googlesource.com/changes/?q=status:merged&n=2&N=002e4203000187d5
With this new query, I was hoping that I'll get another 2 new query results, since I provided the _sortkey as a cursor of my previous search results.
However, it's really weird that this new query returns exactly the same results as the previous query, instead of the next 2 results as I expected. It seems like providing "N=002e4203000187d5" has no effect at all.
Does anybody know why using _sortkey to resume my query doesn't work?
I chatted with one of the developers at Google, and he confirmed that _sortkey has been removed from the newer versions of Gerrit they are running at android-review and gerrit-review. The N= parameter is no longer valid. The documentation will be updated to reflect this.
The alternative is to use &S=x to skip x results, which I tested and works well.
sortkey is deprecated in Gerrit v2.9 -
see the (Gerrit) ReleaseNotes-2.9.txt, under REST API - Changes:
[[sortkey-deprecation]]
Results returned by the [query changes] endpoint are now paginated using offsets instead of sortkeys.
The sortkey and sortkey_prev parameters on the endpoint are deprecated.
The results are now paginated using the --limit (-n) option to limit the number of results, and the -S option to set the start point.
Queries with sortkeys are still supported against old index versions, to enable online reindexing while clients have an older JS version.
See also here -
PSA: Removing the "sortkey" field from the gerrit-on-borg query interface:
...
Our solution is to kill the sortkey field and its related search operators (sortkey_before, sortkey_after, and resume_sortkey).
There are two ways you can achieve similar functionality.
Add "&S=" to your query to skip a fixed number of results.
(Note that this redoes the search so new results may have jumped ahead and
you might process the same change twice.
This is true of the resume_sortkey implementation as well,
so your code should already be able to handle this.)
Use the before/after operators.
Instead of taking the sortkey field from the last returned change and
using it in a resume_sortkey operator, you take the updated field from
the last returned change and use it in a before operator.
(This has slightly different semantics than the sortkey field, which
uses the change number as a tiebreaker when changes have similar updated times.)
...

How do I filter items returned by list to exclude files last modified by me?

Looking at the results of list, there is a lastModifyingUserName, but not a userid or other concrete reference to a user such that I can strongly verify that the file was last modified by me or someone else.
I can approximate this behavior using a string comparison of my user profile information, but this isn't an exact check.
I also looked at the timestamps, and timestamps for a file that was modified by me don't seem to line up, so it doesn't look like I can do this using timestamps either, which looks like a bug in and of itself, e.g.:
"modifiedByMeDate": "2013-01-31T02:25:26.738Z",
"modifiedDate": "2013-01-31T02:29:58.363Z",
Google are working on improving this so that there is consistency between the actor returned in the lastModifyingUserName field and the permission ID.
Right now I agree with you it is pretty impossible, sorry.