How to send query parameters for gmail api for list_user_messages? - ruby

I am trying to send query parameters to fetch list of messages via gmail api https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list
Here is my code
message_list = gmail.list_user_messages user_id
It returns the message list
response -
"messages": [
{
"id": "16641115eca503dc",
"threadId": "16641115eca503dc"
},
Now I want to pass the query parameters
params = {userId: 'me',
maxResults: 1,
pageToken: pageToken}
message_list = gmail.list_user_messages(params)
But it is not working as expected. Please share the correct way to add query parameters.

Go to documentation. Use 'Try this API' option and there you can learn about query params like 'is:unread' ,'from:some#abc.com' etc.
If you want to know about more about valid query strings like 'is:unread' then you can use gmail search options and generate valid query strings.
Edit: Search operator documentation

Related

How to prevent unnecessary G Suite API data consumption?

I am currently consuming data from the G Suite API.
An inconvenience I have found is that for some of the APIs the number of resources available might be quite large.
For instance, when I consume the Users:list API (https://www.googleapis.com/admin/directory/v1/users), given the number of resources and the maximum number of results per query I need to perform a significant number of queries. Find below an example JSON response:
{
"kind": "admin#directory#users",
"etag": "\"WqpSTs-zelqnIvn63V............................/v3ENarMfXkTh9ijs3OVkQRoUSVU\"",
"users": [
{
"kind": "admin#directory#user",
"id": "7720745322191632224007",
"etag": "\"WqpSTs-zelqnIvn63V........................PfcSmik3zEJwHAl1UbgSk\"",
"primaryEmail": ...,
...
},
{
"kind": "admin#directory#user",
"id": "227945583287518253104",
"etag": "\"WqpSTs-zelqnIvn63V..........-zY30eInIGOmLI\"",
"primaryEmail": ...,
...
},
...
N-users
...
]
}
I am running this query several times a day.
Ideally I would only retrieve the resources that have changed and the new ones, excluding from the response the ones that have not changed.
Is it possible to do that? If so, how?
Thank you in advance for your answers.
You could create custom attributes for your users, and then filter your requests using the query parameter according to your custom attribute.
Or define exactly what you mean by "changed" or "not changed" as the user properties will change on every login to update the last login attribute.
Update:
You can watch for changes on the list of users in your domain by supplying an address to receive notifications in a POST request to the watch endpoint:
https://www.googleapis.com/admin/directory/v1/users/watch
References:
Users.watch
Custom User Fields
Query string for User fields

Use result from jdbc request for the next request

I am using JDBC to query on azure sql in JMeter. I was able to successfully get the response. see below
otp
100940
In the Result variable name the value is OTP
My next step in Http request POST method, see below
{
"id": ${requestId},
"otp": "${OTP}",
"requestId": "123456"
}
as you can see otp is parameterized.
But in actual request see below;
POST data:
{
"id": 506,
"otp": "[{otp=100940}]",
"requestId": "123456"
}
how can I concatenate so that I only get the actual otp value without the [{otp=}]
You can add Regular Expression Extractor to extract number from OTP variable
Choose Apply To: JMeter Variable and write OTP and use regular expression as:
otp=(\d+)
And use Template $1$ and Match No. 1
JMeter Variable Name to use - extraction is to be applied to the contents of the named variable
If your response is this otp 100940, use below Regular Expression to extract it:
Now, you can use anywhere OTP value using ${OTP} variable
{
"id": ${requestId},
"otp": "${OTP}",
"requestId": "123456"
}

What is query_hash in instagram?

I was working for the first time on graphql, and I saw that Instagram hash their queries.
I searched something, but I don't know if it is correct. The hash is like a persistedquery stored in a cache memory?
Or am I wrong?
Example: this is my request payload
{
"operationName":"user",
"variables":{},
"query":"query user {\n users {\n username\n createdAt\n _id\n }\n}\n"
}
this is instagram:
query_hash: 60b755363b5c230111347a7a4e242001
variables: %7B%22only_stories%22%3Atrue%7D
(it is in urlencode mode).
Now, how could I hash my query? I'm using NodeJS as backend and react js as frontend.
I would like to understand how it works x)! Thank you guys!
The persisted query is used to improve GraphQL network performance by reducing the request size.
Instead of sending a full query which could be very long, you send a hash to the GraphQL server which will retrieve the full query from the key-value store using the hash as the key.
The key value store can be memcached, redis, etc
The Apollo Server comes with automated persisted queries out of the box. I recommended gives it a try. They have publish a blog about it. https://blog.apollographql.com/automatic-persisted-queries-and-cdn-caching-with-apollo-server-2-0-bf42b3a313de
If you want to build your own solution, you can use this package to do the hashing yourself https://www.npmjs.com/package/hash.js
query_hash (or query_id) does not hash the variables or the parameters, it hashes the payload.
Lets say your actual path is /graphql and your payload is
{
"user": {
"profile": [
"username",
"user_id",
"profile_picture"
],
"feed": {
"posts": {
"data": [
"image_url"
],
"page_size": "{{variables.max_count}}"
}
}
}
}
Then this graphql payload will be hashed and it becomes d4d88dc1500312af6f937f7b804c68c3. Now instead of doing that on /graphql you do /graphql/query/?query_hash=d4d88dc1500312af6f937f7b804c68c3. This way you hashed the payload, as in you hashed the "keys" that are required from the graphql. So when you pass variables as a param then the payload does not actually change, because the variables are constant as well, and you are changing them on the backend, and not in the payload.

ServiceNow REST API: return single column

Is there a way to perform a REST call to ServiceNow REST API that returns a single column of a table? I would like to query the server table for only the names of the servers and not have the entire record containing some 50 plus fields returned.
The latest REST Table API (as of Eureka, I think) supports the parameter sysparm_fields, which allows you to specify a comma-delimited list of fields to include in the response:
This URL template:
https://YOURINSTANCENAME.service-now.com/api/now/v1/table/incident?sysparm_fields=number,short_description,caller_id.name
Would give you a result with something like:
{
"result": [
{
"caller_id.name": "",
"short_description": "Unable to get to network file shares",
"number": "INC0000002"
}
]
}

Scraping, My Query Parameters Are Wrong

I'm on a website using Ruby and Mechanize to pass a POST query to a site. The query that gets to the site, based on firebug, looks like this
param.PrdNo=-1&param.Type=Prop&param.RequestType=Normal&param.PropParams%5B0%5D.CrId=Base-MLB+Su+Washington+Na%40Atlanta+Brave
The QUERY I pass in my ruby code is this
QUERY = { "param.PrdNo" => "-1",
"param.Type" => "Prop",
"param.RequestType" => "Normal",
"param.PropParams[0].CrId" => "Base-MLB+Su+Washington+Na#Atlanta+Brave"}
doc.agent.post(url, QUERY, content_type)
The logger prints out the following
D, [2014-08-10T14:46:24.844744 #15801] DEBUG -- : query: "param.PrdNo=-1&param.Type=Prop&param.RequestType=Normal&param.PropParams%5B0%5D.CrId=Base-MLB%2BSu%2BWashington%2BNa%40Atlanta%2BBrave"
How do I get my code to make a query that looks like the query from firebug?
You could post the string:
vars = "param.PrdNo=-1&param.Type=Prop&param.RequestType=Normal&param.PropParams%5B0%5D.CrId=Base-MLB+Su+Washington+Na%40Atlanta+Brave"
doc.agent.post url, vars, content_type
It will get sent as the raw post body.

Resources