I want to get the oldest email in GMail inbox. How can I do that with the minimum number of API calls?
One way to do it could be to get the total number of emails from Users:getProfile API and then use User.messages:list API to get the last page using "pageToken" query parameter by using the formula
pageToken = totalMessages/50
to get the list of messages from the last page of my inbox and then using the mid of the last message in the list to fetch the oldest email.
I am just wondering if there is a better way to do this? I could not figure out other ways to do it from the documentation. Any search filter that will fetch me the oldest email?
User.messages.list contains a paramter called q which can be used for searching.
https://www.googleapis.com/gmail/v1/users/userId/messagesq=before%3A2008%2F01%2F01&access_token={token}
Basicly before:2008/01/01 is sent just like searching in the gmail web app return all the emails before that date.
The trick here will be narrowing down your search. Gmail was released on 2004. Which gives yo possible start between 2018 and 2004 split it in half
before:2011/01/01 (there were mails split it in half again)
before:2007/01/01 (there were no mails must be between 11 and 7)
before:2009/01/01 (...)
There is a term for this method of searching but i cant remember it right now. Basically you keep dividing it by two and finding out where the result must be.
Related
Not sure if this is even possible - but we are looking for a way to trigger mailchimp newsletters based on a custom field value in a Wordpress website.
Basically we will have a field value that holds "the number of miles" a person has walked based on the data they enter. We will be calculating the "total miles".....when they reach 100 miles for example we will need an email to trigger from Mailchimp....then 200 miles will trigger a 2nd email and so on....
Does anyone know if this can even be done with Mailchimp? If not is there a better approach to handling this?
THANK YOU!
If you are familiar with Python, I'd recommend using a Jupyter notebook for this to cut down on development work. You could set it to run at regular intervals checking the status of each user (running either on your computer or a server), then updating the merge tag of the status in mailchimp. You can have automations that are triggered when the merge tag of distance is a specific value, say 100 they get the 100 email, 200 they get the 200 email. (You could also do it so when a user hits a certain milestone their merge tag is updated in MailChimp but from my experience that's a little more work.)
Net net there are a few ways to achieve your goal but I think using a Python notebook using pandas to manipulate the data and the mailchimp3 mailchimp API client would be the lightest lift.
TIP: Mailchimp currently has a bug where merge tags information is not always accurately represented in the UI. So for example if via the API you added 500 people with the Distance merge value of 200, and checked that via the UI how many people had a value of 200 for Distance you would likely see an inaccurate number displayed for the count in the UI. If you export the list, you will see the correct number that is reflected in your API update. To be clear, in some cases UI does not display the accurate number for users with that merge tag or value, but if you export the list with that merge tag/value via the UI it should match what you pushed to the API. This is currently an open ticket.
My app needs to sync up with the youtube api to pull in info about any new videos. But in the PlaylistItems.list docs, I don't see any kind of "sort order" or date filtering parameters.
Is there a way to do this, or do I need to download all the playlist items every time I want to check if there is a new video?
You are going to have to download the playlist your self and then sort them locally. As you have already seen there is no way to sort them or filter the number of rows.
I think there is a really old feature request for the ability to sort. Playlist API: Add support for sorting playlist items response
What I find interesting is that they still haven't done more then set the status to "Acknowledged" and it took them two years to do that.
I guess this goes back to the question I always have who's responsibility is it to sort the data? The API or the developer? It appears that Google thinks its the developer.
I found a post on my travels that said that all play lists generated are ordered from newest first to oldest. Excepting personal playlists that the user creates which are ordered as they were added. So first added will be first in list. So [0] node is first in list response.
On the other hand, you can use the [publishedAt] property to get a time stamp.
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=.........
[snippet] => Array ([publishedAt]=> 2010-05-12T23:57:34.000Z
Or
https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&channelId=........
However please note, this call will give EVERYTHING from the channel. Video uploads and playlists created.
As there are many call possibilities in the api, I am sure that you can find the right one that works for your needs.
I would like to use the Outlook REST API to display the messages in a mail folder and group messages by conversations, like you have in any modern webmail.
For example with inbox, I would request using a first query such as <mailuri>/inbox/messages?$select=ConversationId (by default it is reverse chronological order)
It is not sufficient to group this request results by ConversationId because some emails may not be in inbox (think of sentmails) or they may be paginated and not returned in the first page.
Consequently, for each distinct ConversationId I need to perform another REST request, for retrieving participants or simply counting the emails in the conversation. I may use the new batch request to do this.
There are a lot of requests involved. Is there a better solution ?
As you've probably realized the REST API doesn't directly provide a way to work with conversations as an entity. This is something that we have on our roadmap to improve.
With the current state of the API what you're describing is basically the right approach. You could possibly defer the second request to "fill in" a conversation until the user selects it.
You can actually use this endpoint to cover both inbox and sentitems
https://outlook.office.com/api/v2.0/me/messages/?$select=ConversationId & $filter=ConversationId eq '${params.conversationId}'
In previous version of MailChimp API there was option to get specific list of members. You was able to send list of emails and get those members.
In version 3.0 there is only option to get ALL members or to get ONE specific members:
/lists/{list_id}/members => get all Members
/lists/{list_id}/members/{subscriber_hash} => get ONE member by Email
So both option is not good. What If I have 100 emails and I want to get that 100 members from my Mailchimp List which have 20k subscribers.
With first option I would need to get all 20k members from the list and then take the 100 which I need? That's bad.
With second option I would need to loop 100 emails and send 100 request to get each member.
Is there any workaround to get list of members querying by multiple emails in v3.0?
In API I can't find filter/query like this neither.
I would make a request to get all the 20k members, and with a simply linq/foreach/filter. With this You will get your 100 members in JSON so I think thats the fastest, and easiest way to do it.
You can use batch operations, but that's almost the same like you loop requests, and harder to get the results and much slower ( need to check the batch is ready what can take several minutes, and wait for it, than get the result url, what will give you a .tar.gz so need to unzip twice, etc) So I think this is a dead idea for "GET" requests.
A web application sends an email on behalf of a UserA to UserB, using the new Gmail API (Users.messages: send).
The synchronous response contains threadId, messageId which are stored in the database.
We then query the history API for any changes in user's inbox (Users.history: list).
Is there an efficient way to get all the updates since last sync (new replies, read/unread changes)?
One implementation that we tried was to filter the history API results through a custom label. Unfortunately, we noticed that once a thread/message is tagged with a specific label any subsequent responses are not labeled automatically and new replies are not included in the history API response.
A second approach was to query threads using gmail advanced search for a particular label and date (e.g. after:2014/08/29 label:MY_LABEL). The problem was that gmail does not return threads that were created before 2014/08/29 but had a reply on that date.
Any scalable suggestions would be greatly appreciated.
Not sure I understand here, users.history.list was made exactly for this. Given a previous historyId, you can then call history.list(previousHistoryid), iterate through the results to find all the message Ids that have been updated since the previous historyId. Then call messages.get() on all of those--for any messages you already knew about you can just call format=MINIMAL (to see label updates), and for new messages you can use a different format to get the message content if you need it.