最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Get Inbox Email using Nylas (only important email filter!) - Stack Overflow

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

Hopes 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...

发布评论

评论列表(0)

  1. 暂无评论