Im using Nylas to curl the last 5 Emails for a Web Project.
The issue I have is that its list from all mails i got, the last 5 (Spam, Advertising or Buisness) mixed.
Is there maybe a nother solution?
const NYLAS_API_KEY = process.env.NEXT_PUBLIC_NYLAS_API_TOKEN; // Replace with your Nylas API Key
/**
* Fetches messages for a given Nylas grant ID with an optional limit.
* @param {string} grantId - The Nylas grant ID.
* @param {number} [limit=5] - The number of messages to fetch (default is 5).
* @returns {Promise<object>} - The response data from the Nylas API.
* @throws {Error} - Throws an error if the API call fails.
*/
export const getMessages = async (grantId, limit = 5) => {
try {
const response = await axios.get(
`/${grantId}/messages`,
{
headers: {
'Accept': 'application/json, application/gzip',
'Authorization': `Bearer ${NYLAS_API_KEY}`,
'Content-Type': 'application/json'
},
params: {
// Filtering for important emails and excluding promotional category emails
//search_query_native: 'CATEGORY_PERSONAL', //NOT WORKING
//in: IMPORTANT, //NOT WORKING
limit
}
}
);
return response.data.data;
} catch (err) {
throw new Error(
console.error(err)
);
}
}; ```
Im using Nylas to curl the last 5 Emails for a Web Project.
The issue I have is that its list from all mails i got, the last 5 (Spam, Advertising or Buisness) mixed.
Is there maybe a nother solution?
const NYLAS_API_KEY = process.env.NEXT_PUBLIC_NYLAS_API_TOKEN; // Replace with your Nylas API Key
/**
* Fetches messages for a given Nylas grant ID with an optional limit.
* @param {string} grantId - The Nylas grant ID.
* @param {number} [limit=5] - The number of messages to fetch (default is 5).
* @returns {Promise<object>} - The response data from the Nylas API.
* @throws {Error} - Throws an error if the API call fails.
*/
export const getMessages = async (grantId, limit = 5) => {
try {
const response = await axios.get(
`https://api.us.nylas/v3/grants/${grantId}/messages`,
{
headers: {
'Accept': 'application/json, application/gzip',
'Authorization': `Bearer ${NYLAS_API_KEY}`,
'Content-Type': 'application/json'
},
params: {
// Filtering for important emails and excluding promotional category emails
//search_query_native: 'CATEGORY_PERSONAL', //NOT WORKING
//in: IMPORTANT, //NOT WORKING
limit
}
}
);
return response.data.data;
} catch (err) {
throw new Error(
console.error(err)
);
}
}; ```
Share
Improve this question
asked Nov 20, 2024 at 10:34
LinusNeedTechTipsLinusNeedTechTips
333 bronze badges
1
- Maybe Aurinko API will cooperate better? docs.aurinko.io/unified-apis/email-api – Alexey Commented Dec 3, 2024 at 21:09
1 Answer
Reset to default 0Hopes this helps, this is how i integrated it in my system and it works.
const options = {
method: 'GET',
url: `${this.nylasHost}/grants/${this.grantId}/messages?in=UNREAD`,
headers: { authorization: this.authHeader }
};
...make the request...