Can creationTime and other Directory meta-fields be used in a query? - google-admin-sdk

I'm trying to filter the list of users returned from Directory.Users.List, and want to use the creationTime value in the filter. According to this:
Search for users
...you can use Date fields in comparisons, however when I try something like:
creationTime>=2016-06-30 (or the same value quoted)
...I get:
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
{
"code" : 400,
"errors" : [ {
"domain" : "global",
"message" : "Invalid Input: creationTime>=2016-06-30",
"reason" : "invalid"
} ],
"message" : "Invalid Input: creationTime>=2016-06-30"
}
The message isn't particularly helpful - is this a syntax issue with the query, or is it the case that the field isn't available for query (it isn't listed in that article, but it is part of the JSON response)?
The article specifies the format for Date field queries, however this field also includes a time component, so I tried to also replicate the exact format that shows in the JSON, with the same result.
Also, same result in the Try it! section of the Users reference page.
Also also, tried using a numeric value (Date.getTime(), in effect) - same error.
Thanks...
P.S. Interestingly, Google does document how to search on date fields for Chromebooks, and it's entirely different than they imply for users. I still can't use creationTime with this, but it does work for Chromebooks. The other part of this is that it refers to fields that aren't documented, and why I try to use the documented field (e.g. lastSync vs. sync), it fails with the same message. This whole thing seems half-baked.
View Chrome device information

Only the fields listed in the table are searchable via the users.list search.
A workaround (I don't know if this is suitable for you) may be to push the data you want to use in a search into custom user fields. These fields are searchable.

Related

how to change errors in Django rest framework like PK to ID

{
"status": 400,
"errors": [
"designation Invalid pk "2" - object does not exist.",
"provincedetails Invalid pk "10" - object does not exist."
]
}
I know why this errors is throwing because relation object is not exist so..
But I want to customize this error like to remove PK and add ID, is that possible to do?
You can implement a custom Exception handler, as described in the docs
There you can search for pk (mind the spaces!) and replace it with id. Beware that this is hacky. If doing it via localization is easier, I would definitly use that option instead. That being said, I don't know why you would want to change form pk to id in the first place.
Did not try to do that, but looks like error text holds inside
django-rest-framework/rest_framework/locale/{LANG_CODE}/LC_MESSAGES/django.po
So you can change error message using custom internationalization

Facebook graph api in /act_<account-id>/adcreatives

The call to /adcreatives edge on adaccount api (/act_<>/) is failing with the following. I was able to narrow it down to a particular creative, which fails when I request object_story_spec field
"error_user_title": "First Dof Value Should Match Object Story Spec Field",
"error_user_msg": "For a Degrees of freedom enabled ad, the first value of Asset Feed Spec field should match the corresponding field in Object Story Spec.", ```
I haven't been able to find any reference to this error code ("error_subcode": 2446211 ), or the issue anywhere
use /me/adaccounts then use fields adcreative to report

How to run a combination of query and filter in elasticsearch?

I am experimenting using elasticsearch in a dummy project in django. I am attempting to make a search page using django-elasticsearch-dsl. The user may provide a title, summary and a score to search for. The search should match all the information given by the user, but if the user does not provide any info about something, this should be skipped.
I am running the following code to search for all the values.
client = Elasticsearch()
s = Search().using(client).query("match", title=title_value)\
.query("match", summary=summary_value)\
.filter('range', score={'gt': scorefrom_value, 'lte': scoreto_value})
When I have a value for all the fields then the search works correctly, but if for example I do not provide a value for the summary_value, although I am expecting the search to continue searching for the rest of the values, the result is that it comes up with nothing as a result.
Is there some value that the fields should have by default in case the user does not provide a value? Or how should I approach this?
UPDATE 1
I tried using the following, but it returns every time no matter the input i am giving the same results.
s = Search(using=client)
if title:
s.query("match", title=title)
if summary:
s.query("match", summary=summary)
response = s.execute()
UPDATE 2
I can print using the to_dict().
if it is like the following then s is empty
s = Search(using=client)
s.query("match", title=title)
if it is like this
s = Search(using=client).query("match", title=title)
then it works properly but still if i add s.query("match", summary=summary) it does nothing.
You need to assign back into s:
if title:
s = s.query("match", title=title)
if summary:
s = s.query("match", summary=summary)
I can see in the Search example that django-elasticsearch-dsl lets you apply aggregations after a search so...
How about "staging" your search? I can think if the following:
#first, declare the Search object
s = Search(using=client, index="my-index")
#if parameter1 exists
if parameter1:
s.filter("term", field1= parameter1)
#if parameter2 exists
if parameter2:
s.query("match", field=parameter2)
Do the same for all your parameters (with the needed method for each) so only the ones that exist will appear in your query. At the end just run
response = s.execute()
and everything should work as you want :D
I would recommend you to use the Python ES Client. It lets you manage multiple things related to your cluster: set mappings, health checks, do queries, etc.
In its method .search(), the body parameter is where you send your query as you normally would run it ({"query"...}). Check the Usage example.
Now, for your particular case, you can have a template of your query stored in a variable. You first start with, let's say, an "empty query" only with filter, just like:
query = {
"query":{
"bool":{
"filter":[
]
}
}
}
From here, you now can build your query from the parameters you have.
This is:
#This would look a little messy, but it's useful ;)
#if parameter1 is not None or emtpy
#(change the if statement for your particular case)
if parameter1:
query["query"]["bool"]["filter"].append({"term": {"field1": parameter1}})
Do the same for all your parameters (for strings, use "term", for ranges use "range" as usual) and send the query in the .search()'s body parameter and it should work as you want.
Hope this is helpful! :D

Include Adset details Insights query

Using the Facebook Marketing API (Graph API), I use the following (simplified for brevity) query:
act_xxxxxx/insights?level=adset&fields=date_start,date_stop,clicks,adset_name
This gives me a result like this:
{
"data": [
{
"date_start": "2019-01-01",
"date_stop": "2019-01-30",
"clicks": "999",
"adset_name": "Awesome Adset"
}
] //paging info removed, not relevant
}
For each node in data, I would like to include some properties from the adset, like end_time,start_time,lifetime_budget,daily_budget.
I have looked into expanding fields, but there does not seem to be an adset field I can expand on here.
Is there a way to include adset fields like lifetime_budget, so I can get the results in one go?
Right now, query adsets separately and join afterwards, but I think there must be a way to get it in one resultset.
You could query adsets and ask for all the fields you need adding with the parenthesis notation each kind of params you need, as example, for ask about all the adsets with budgets info and bid strategy of an adAccount with insights with specified metrics, you can use the following:
act_XXXX/adsets?fields=insights{clicks,spend,cpc},lifetime_budget,daily_budget,name,start_time,end_time
Hope this help

Handling errors with the Ember Data JSON-API adapter

Errors on attributes located within related models is now my problem. I can see the errors on these related models by doing model.errors.content or model.errors.messages but if I want to check a particular attribute on a related model in order to highlight field errors I get null or undefined values.
See below screen shot for more info
Invaild Error object:
Model After error: In this object i am getting the attribute and message but i use model.get("errors.phone"
My best guess is, you need to update your error serializer to send data in a format expected by Ember Data JSON Adapter.
It's best explained in detail in
this stackoverflow answer, but as a gist you should format your data in a following way:
{
"errors":
[
{
"detail": "is invalid",
"source": {
"pointer": "data/attributes/phone"
}
}
]
}
The pointer must correspond to your model attribute, so phone in this example.