TechniekCollegeRotterdam / anonymous-mail-api

0 stars 0 forks source link

Gmail API Creating Filter gives 500 error #3

Open JeremiahKoeiman opened 4 years ago

JeremiahKoeiman commented 4 years ago

Hi,

I am trying to make emails go automatically into gmails spam box. I want to do this by creating a gmail filter for every email a user gives to be a spam email. I work with Cloud Firestore to get all the given emails a user has given to be a spam emailaddress. I want to make a gmail filter that goes through each of the saved emailaddresses and replaces the email labels in the gmail inbox from Inbox to Spam. I have tried this with the following code:

exports.addSpammer = async (req, res) => {

    const gmail = google.gmail({version: 'v1', oAuth2Client})

    try {
        const data = await db.collection('spammedEmails').where('username', '==', req.user.username).get()

        if (data.empty) {
            return res.status(404).json({error: 'No spammed email addresses found'})
        } else {

            data.map(async (doc) => {
                await gmail.users.settings.filters.create({
                    userId: 'me',
                    id: passomatic(1),
                    criteria: {
                        from: `${doc.data().spammedEmail}`
                    },
                    action: {
                        removeLabelIds: [
                            "INBOX"
                        ],
                        addLabelIds: [
                            "SPAM"
                        ]
                    }
                })
            })
        }

        return res.status(200).json('Spammer added')
    } catch (err) {
        if (err.code === "auth/id-token-expired")
            return res.status(401).json({general: 'Login expired, please login again'});
        else
            return res.status(500).json({error: err.code})
    }
} 

And if I try this out in Postman I get the following: Postman example

And in my editor I also have no error message in my console: No console error

So, is there some who knows what's going on, why it's not working and how I can fix it? Thanks in advance.

jordyvandomselaar commented 4 years ago

Hi @JeremiahKoeiman ,

Try changing

return res.status(500).json({error: err.code})

to

throw error;

You should be able to see more logging in your terminal.

Because you're catching it, Node.js' error handler doesn't trigger. You have to throw it again before Node knows something went wrong.

JeremiahKoeiman commented 4 years ago

Thanks! I'll try it out

JeremiahKoeiman commented 4 years ago

Thank you for your reply. What you said worked but now I get this:

 functions: Beginning execution of "api"
!  Google API requested!
   - URL: "https://www.googleapis.com/oauth2/v4/token"
   - Be careful, this may be a production service.
!  Google API requested!
   - URL: "https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=OdpaktvhTYc&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM"
   - Be careful, this may be a production service.
!  Google API requested!
   - URL: "https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=YpfyAyudmuj&criteria%5Bfrom%5D=bla%40gmail.nl&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM"
   - Be careful, this may be a production service.
!  Google API requested!
   - URL: "https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=Fyfmqxbjam&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM"
   - Be careful, this may be a production service.
!  Google API requested!
   - URL: "https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=qxXDiyru&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM"
   - Be careful, this may be a production service.
!  Google API requested!
   - URL: "https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=tLuvapit&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM"
   - Be careful, this may be a production service.
!  Google API requested!
   - URL: "https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=hntztkyAory&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM"
   - Be careful, this may be a production service.
!  Google API requested!
   - URL: "https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=WdnJnbdydQ&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM"
   - Be careful, this may be a production service.
!  Google API requested!
   - URL: "https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=HjiBaaet&criteria%5Bfrom%5D=9001603%40student.zadkine.nl&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM"
   - Be careful, this may be a production service.
!  Google API requested!
   - URL: "https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=pYTvtdrwikf&criteria%5Bfrom%5D=test%40mail.nl&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM"
   - Be careful, this may be a production service.
i  functions: Finished "api" in ~1s
>  GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=OdpaktvhTYc&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 09:12:49 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '204934469753-t3ctmp8b140ok7trbhet2162umd2bjft.apps.googleusercontent.com',
>        _clientSecret: '5_xwZP1vaEwzRWP60n3JhB0g',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=OdpaktvhTYc&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        id: 'OdpaktvhTYc',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }
>  (node:5768) UnhandledPromiseRejectionWarning: Error: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  (node:5768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
>  (node:5768) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
>  (node:5768) UnhandledPromiseRejectionWarning: Error: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  (node:5768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
>  (node:5768) UnhandledPromiseRejectionWarning: Error: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  (node:5768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
>  (node:5768) UnhandledPromiseRejectionWarning: Error: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  (node:5768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
>  (node:5768) UnhandledPromiseRejectionWarning: Error: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  (node:5768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 5)
>  (node:5768) UnhandledPromiseRejectionWarning: Error: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  (node:5768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 6)
>  (node:5768) UnhandledPromiseRejectionWarning: Error: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  (node:5768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 7)
>  (node:5768) UnhandledPromiseRejectionWarning: Error: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  (node:5768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 8)
>  (node:5768) UnhandledPromiseRejectionWarning: Error: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5)
>  (node:5768) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 9)
>  GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=WdnJnbdydQ&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 09:12:49 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '204934469753-t3ctmp8b140ok7trbhet2162umd2bjft.apps.googleusercontent.com',
>        _clientSecret: '5_xwZP1vaEwzRWP60n3JhB0g',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=WdnJnbdydQ&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        id: 'WdnJnbdydQ',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }
>  GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=qxXDiyru&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 09:12:49 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '204934469753-t3ctmp8b140ok7trbhet2162umd2bjft.apps.googleusercontent.com',
>        _clientSecret: '5_xwZP1vaEwzRWP60n3JhB0g',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=qxXDiyru&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        id: 'qxXDiyru',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }
>  GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=hntztkyAory&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 09:12:49 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '204934469753-t3ctmp8b140ok7trbhet2162umd2bjft.apps.googleusercontent.com',
>        _clientSecret: '5_xwZP1vaEwzRWP60n3JhB0g',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=hntztkyAory&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        id: 'hntztkyAory',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }
>  GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=Fyfmqxbjam&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 09:12:49 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '204934469753-t3ctmp8b140ok7trbhet2162umd2bjft.apps.googleusercontent.com',
>        _clientSecret: '5_xwZP1vaEwzRWP60n3JhB0g',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=Fyfmqxbjam&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        id: 'Fyfmqxbjam',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }
>  GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=HjiBaaet&criteria%5Bfrom%5D=9001603%40student.zadkine.nl&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 09:12:49 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '204934469753-t3ctmp8b140ok7trbhet2162umd2bjft.apps.googleusercontent.com',
>        _clientSecret: '5_xwZP1vaEwzRWP60n3JhB0g',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=HjiBaaet&criteria%5Bfrom%5D=9001603%40student.zadkine.nl&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        id: 'HjiBaaet',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }
>  GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=pYTvtdrwikf&criteria%5Bfrom%5D=test%40mail.nl&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 09:12:49 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '204934469753-t3ctmp8b140ok7trbhet2162umd2bjft.apps.googleusercontent.com',
>        _clientSecret: '5_xwZP1vaEwzRWP60n3JhB0g',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=pYTvtdrwikf&criteria%5Bfrom%5D=test%40mail.nl&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        id: 'pYTvtdrwikf',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }
>  GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=tLuvapit&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 09:12:49 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '204934469753-t3ctmp8b140ok7trbhet2162umd2bjft.apps.googleusercontent.com',
>        _clientSecret: '5_xwZP1vaEwzRWP60n3JhB0g',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=tLuvapit&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        id: 'tLuvapit',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }
>  GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=YpfyAyudmuj&criteria%5Bfrom%5D=bla%40gmail.nl&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 09:12:49 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '204934469753-t3ctmp8b140ok7trbhet2162umd2bjft.apps.googleusercontent.com',
>        _clientSecret: '5_xwZP1vaEwzRWP60n3JhB0g',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?id=YpfyAyudmuj&criteria%5Bfrom%5D=bla%40gmail.nl&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        id: 'YpfyAyudmuj',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }
jordyvandomselaar commented 4 years ago

Have a look at this documentation: https://developers.google.com/gmail/api/auth/about-auth

The problem you're running into is that you're not sending a valid token to gmail. You need that so Gmail can determine what app is currently trying to access the api.

JeremiahKoeiman commented 4 years ago

I looked at it and I forgot to add the oAuth client. So I added it and now I get this:

GaxiosError: Login Required.
>      at Gaxios.<anonymous> (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:73:27)
>      at Generator.next (<anonymous>)
>      at fulfilled (D:\Anonymous mail\anonymous-mail\backend\functions\node_modules\googleapis-common\node_modules\gaxios\build\src\gaxios.js:16:58)>      at processTicksAndRejections (internal/process/task_queues.js:97:5) {
>    response: {
>      config: {
>        oAuth2Client: [OAuth2Client],
>        url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?oAuth2Client%5B_eventsCount%5D=0&oAuth2Client%5Bcredentials%5D%5Brefresh_token%5D=1%2F%2F09sq6AZey-ybICgYIARAAGAkSNwF-L9IrGUbJSA362fXoiwfT_HOMSFkUKF4x1j8lUyXmk0I0XWQv_rVFQFfQkp6t4_Xd-G_nYAw&oAuth2Client%5Bcredentials%5D%5Baccess_token%5D=ya29.a0AfH6SMDnFqbJ5jf7w2HDvAaiWeZiQbyeoW54uUE7Nts3Kb9MBWLmzU-995ZQtNjOjJ3zf9h01JrsUfN5xkcaiGOhiIaMdmycwVkc_7F-ULcPeNCuhShDkRDCRLloQJBbTG0L7upL_j3B-mnKNsFP9Qv4EyrGKxjlNqc&oAuth2Client%5BcertificateExpiry%5D=&oAuth2Client%5BcertificateCacheFormat%5D=PEM&oAuth2Client%5B_clientId%5D=515588733829-4ddhgl4avl5i4qe0qnadahve23lflgma.apps.googleusercontent.com&oAuth2Client%5B_clientSecret%5D=Jru7DBV8rfzJYp1Wpz0PkbkK&oAuth2Client%5BredirectUri%5D=https%3A%2F%2Feurope-west2-anonymous-email-app.cloudfunctions.net%2Fapi&oAuth2Client%5BeagerRefreshThresholdMillis%5D=300000&id=OjflgiNCiwa&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>        method: 'POST',
>        paramsSerializer: [Function],
>        headers: [Object],
>        params: [Object: null prototype],
>        validateStatus: [Function],
>        responseType: 'json'
>      },
>      data: { error: [Object] },
>      headers: {
>        'alt-svc': 'h3-27=":443"; ma=2592000,h3-25=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q049=":443"; ma=2592000,h3-Q048=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"',
>        'cache-control': 'private',
>        connection: 'close',
>        'content-encoding': 'gzip',
>        'content-type': 'application/json; charset=UTF-8',
>        date: 'Thu, 04 Jun 2020 11:23:56 GMT',
>        server: 'ESF',
>        'transfer-encoding': 'chunked',
>        vary: 'Origin, X-Origin, Referer',
>        'x-content-type-options': 'nosniff',
>        'x-frame-options': 'SAMEORIGIN',
>        'x-xss-protection': '0'
>      },
>      status: 401,
>      statusText: 'Unauthorized'
>    },
>    config: {
>      oAuth2Client: OAuth2Client {
>        _events: [Object: null prototype] {},
>        _eventsCount: 0,
>        _maxListeners: undefined,
>        transporter: DefaultTransporter {},
>        credentials: [Object],
>        certificateCache: {},
>        certificateExpiry: null,
>        certificateCacheFormat: 'PEM',
>        refreshTokenPromises: Map {},
>        _clientId: '515588733829-4ddhgl4avl5i4qe0qnadahve23lflgma.apps.googleusercontent.com',
>        _clientSecret: 'Jru7DBV8rfzJYp1Wpz0PkbkK',
>        redirectUri: 'https://europe-west2-anonymous-email-app.cloudfunctions.net/api',
>        eagerRefreshThresholdMillis: 300000,
>        [Symbol(kCapture)]: false
>      },
>      url: 'https://www.googleapis.com/gmail/v1/users/me/settings/filters?oAuth2Client%5B_eventsCount%5D=0&oAuth2Client%5Bcredentials%5D%5Brefresh_token%5D=1%2F%2F09sq6AZey-ybICgYIARAAGAkSNwF-L9IrGUbJSA362fXoiwfT_HOMSFkUKF4x1j8lUyXmk0I0XWQv_rVFQFfQkp6t4_Xd-G_nYAw&oAuth2Client%5Bcredentials%5D%5Baccess_token%5D=ya29.a0AfH6SMDnFqbJ5jf7w2HDvAaiWeZiQbyeoW54uUE7Nts3Kb9MBWLmzU-995ZQtNjOjJ3zf9h01JrsUfN5xkcaiGOhiIaMdmycwVkc_7F-ULcPeNCuhShDkRDCRLloQJBbTG0L7upL_j3B-mnKNsFP9Qv4EyrGKxjlNqc&oAuth2Client%5BcertificateExpiry%5D=&oAuth2Client%5BcertificateCacheFormat%5D=PEM&oAuth2Client%5B_clientId%5D=515588733829-4ddhgl4avl5i4qe0qnadahve23lflgma.apps.googleusercontent.com&oAuth2Client%5B_clientSecret%5D=Jru7DBV8rfzJYp1Wpz0PkbkK&oAuth2Client%5BredirectUri%5D=https%3A%2F%2Feurope-west2-anonymous-email-app.cloudfunctions.net%2Fapi&oAuth2Client%5BeagerRefreshThresholdMillis%5D=300000&id=OjflgiNCiwa&criteria%5Bfrom%5D=jeremiahkoeiman1%40gmail.com&action%5BremoveLabelIds%5D=INBOX&action%5BaddLabelIds%5D=SPAM',
>      method: 'POST',
>      paramsSerializer: [Function],
>      headers: {
>        'Accept-Encoding': 'gzip',
>        'User-Agent': 'google-api-nodejs-client/0.7.2 (gzip)',
>        Accept: 'application/json'
>      },
>      params: [Object: null prototype] {
>        oAuth2Client: [OAuth2Client],
>        id: 'OjflgiNCiwa',
>        criteria: [Object],
>        action: [Object]
>      },
>      validateStatus: [Function],
>      responseType: 'json'
>    },
>    code: 401,
>    errors: [
>      {
>        message: 'Login Required.',
>        domain: 'global',
>        reason: 'required',
>        location: 'Authorization',
>        locationType: 'header'
>      }
>    ]
>  }

which is very strange, because I didn't have that before.

jordyvandomselaar commented 4 years ago

That could very well mean that your token has expired. Try clearing data, logging in again and then try running the call again.

JeremiahKoeiman commented 4 years ago

@jordyvandomselaar

I've tried that and it worked (I also forgot to add a parametername), but now I get this:

code: 400,
>    errors: [
>      {
>        message: 'Invalid label SPAM in AddLabelIds',
>        domain: 'global',
>        reason: 'invalidArgument'
>      }
>    ]

while in my code I have this:

body: '{"criteria":{"from":"jeremiahkoeiman1@gmail.com"},"action":{"addLabelIds":["SPAM"],"removeLabelIds":["INBOX"]}}'

which is strange, because if I console log the labels names and id's I get this:

>  - SPAM
>  - SPAM
jordyvandomselaar commented 4 years ago

If you try a different label, does it work?

JeremiahKoeiman commented 4 years ago

No it still doesn't work. I get the same error and I'm sure I spelled it right, because I copy pasted it.

jordyvandomselaar commented 4 years ago

So a different label does not work? like "INBOX"

JeremiahKoeiman commented 4 years ago

I created a new label in Gmail itself called TestLabel and tried it with that but it didn't work. I got the same error.

jordyvandomselaar commented 4 years ago

In that case I think it might be a syntax error, please try reading examples or docs and see if you did something different

JeremiahKoeiman commented 4 years ago

I followed the example from the following website: here but even when I tried it in the API explorer, it still didn't work. Is it possible that this is a bug?

jordyvandomselaar commented 4 years ago

It's unlikely that it's a bug; there'd be a lot more apps with problems if it were =), I'll try and see if it works for me in the api explorer