Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar API Event Get URLEncoding Calendar Id #2229

Closed
atilling opened this issue Jun 9, 2020 · 12 comments
Closed

Calendar API Event Get URLEncoding Calendar Id #2229

atilling opened this issue Jun 9, 2020 · 12 comments
Assignees
Labels
api: calendar Issues related to the Calendar API API. needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue.

Comments

@atilling
Copy link

atilling commented Jun 9, 2020

Environment details

  • OS: AWS Lambda
  • Node.js version: Node.js 12.x
  • npm version:
  • googleapis version: googleapis@39.2.0

Steps to reproduce

calId: conncoll.edu_023hs5hct41vhhibamjbasdkbs@group.calendar.google.com
eventId: irudvea992rumvho9eosunifq8

const cal = google.calendar('v3');
let folderList =[];
let fconf = {};
fconf.auth = jwtClient;
fconf.calendarId = calId;
fconf.eventId = eventId;
const calEvent = await cal.events.get(fconf);
console.log (calEvent);

Return as follows, note the url has %40 if the URL is sent as @ and not %40 the return is correct

{
    "errorType": "Error",
    "errorMessage": "Not Found",
    "code": 404,
    "response": {
        "config": {
            "url": "https://www.googleapis.com/calendar/v3/calendars/conncoll.edu_023hs5hct41vhhibamjbasdkbs%40group.calendar.google.com/events/irudvea992rumvho9eosunifq8",
            "method": "GET",
            "headers": {
                "Accept-Encoding": "gzip",
                "User-Agent": "google-api-nodejs-client/0.7.2 (gzip)",
                "Authorization": "Bearer ya29.c.KpMBzgcRDFBz9Ce8LT7WG9eHdCFxmMAkDgfyXFjVT6T_kT1OwpKsQOzhikjTyjWATQ82jVNWIprLp69tQtrTkazZWk0BFZYYSWg4CNgV_DVG-OLcjtybKccA8LZc4d_vRLxYY0e9o3CozwjtM_5G4T0nKd0Uiv-Rhyc87L0Ovfd-l9fps1VPTWw7bZSazZYIU8C37q9r",
                "Accept": "application/json"
            },
            "params": {},
            "responseType": "json"
        },
        "data": {
            "error": {
                "errors": [
                    {
                        "domain": "global",
                        "reason": "notFound",
                        "message": "Not Found"
                    }
                ],
                "code": 404,
                "message": "Not Found"
            }
        },
        "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, max-age=0",
            "connection": "close",
            "content-encoding": "gzip",
            "content-security-policy": "frame-ancestors 'self'",
            "content-type": "application/json; charset=UTF-8",
            "date": "Mon, 08 Jun 2020 19:57:52 GMT",
            "expires": "Mon, 08 Jun 2020 19:57:52 GMT",
            "server": "GSE",
            "transfer-encoding": "chunked",
            "vary": "Origin, X-Origin",
            "x-content-type-options": "nosniff",
            "x-frame-options": "SAMEORIGIN",
            "x-xss-protection": "1; mode=block"
        },
        "status": 404,
        "statusText": "Not Found"
    },
    "config": {
        "url": "https://www.googleapis.com/calendar/v3/calendars/conncoll.edu_023hs5hct41vhhibamjbasdkbs%40group.calendar.google.com/events/irudvea992rumvho9eosunifq8",
        "method": "GET",
        "headers": {
            "Accept-Encoding": "gzip",
            "User-Agent": "google-api-nodejs-client/0.7.2 (gzip)",
            "Authorization": "Bearer a-bearer-token",
            "Accept": "application/json"
        },
        "params": {},
        "responseType": "json"
    },
    "errors": [
        {
            "domain": "global",
            "reason": "notFound",
            "message": "Not Found"
        }
    ],
    "stack": [
        "Error: Not Found",
        "    at Gaxios.<anonymous> (/var/task/node_modules/gaxios/build/src/gaxios.js:73:27)",
        "    at Generator.next (<anonymous>)",
        "    at fulfilled (/var/task/node_modules/gaxios/build/src/gaxios.js:16:58)",
        "    at processTicksAndRejections (internal/process/task_queues.js:97:5)"
    ]
}
@JustinBeckwith JustinBeckwith added api: calendar Issues related to the Calendar API API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jun 9, 2020
@atilling
Copy link
Author

atilling commented Jun 9, 2020

in a chat with support it seems that the format for the CalendarId has changed https://gsuiteupdates.googleblog.com/2020/05/change-to-format-of-secondary-calendar.html the logic may need to be updated to accommodate that change.

@JustinBeckwith
Copy link
Contributor

JustinBeckwith commented Jun 10, 2020

Greetings! I just tried something similar with the latest version of the module, 52.1.0, and everything appears to be working. I used this code:

const path = require('path');
const {google} = require('googleapis');
const {authenticate} = require('@google-cloud/local-auth');

async function main() {
  const auth = await authenticate({
    scopes: ['https://www.googleapis.com/auth/calendar'],
    keyfilePath: path.resolve('../keys/oauth2.keys.json'),
  });
  google.options({auth});
  const calendar = google.calendar('v3');
  const res = await calendar.events.get({
    calendarId: 'google.com_3gbcnczzzzzzzzzzzzz8abftc@group.calendar.google.com',
    eventId: 'zzzzzzzzzzzzzzzz',
  });
  console.log(res.data);
}
main();

Could I trouble you to update to the latest version of the module and let us know if you run into the same problem?

Note: to run this code:

mkdir eventy
cd eventy
npm init -y
npm install googleapis @google-cloud/local-auth
touch server.js
# put the code above in server.js
node server.js

@JustinBeckwith JustinBeckwith added the needs more info This issue needs more information from the customer to proceed. label Jun 10, 2020
@JustinBeckwith JustinBeckwith assigned atilling and unassigned sofisl Jun 10, 2020
@atilling
Copy link
Author

NPM is gave me version 47 and the error still happens. What is the correct way to grab version 52?

@JustinBeckwith
Copy link
Contributor

The best way is to update the version in your package.json, and run 'npm install'.

@atilling
Copy link
Author

atilling commented Jun 11, 2020

Updated to 52.1.0 still 404 Error:

{
    "errorType": "Error",
    "errorMessage": "Not Found",
    "code": 404,
    "response": {
        "config": {
            "url": "https://www.googleapis.com/calendar/v3/calendars/conncoll.edu_023hs5hct41vhhibamjbasdkbs%40group.calendar.google.com/events/irudvea992rumvho9eosunifq8",
            "method": "GET",
            "userAgentDirectives": [
                {
                    "product": "google-api-nodejs-client",
                    "version": "4.3.0",
                    "comment": "gzip"
                }
            ],
            "headers": {
                "x-goog-api-client": "gdcl/4.3.0 gl-node/12.16.3 auth/6.0.1",
                "Accept-Encoding": "gzip",
                "User-Agent": "google-api-nodejs-client/4.3.0 (gzip)",
                "Authorization": "Bearer ya29.c.KpMBzgdYwb6AVurs1gP9fDRw4DMA1ys6ux77JueidiXXeloVDj0vw_hrAcu-souTl28QTrBIAYgz8OFqu7PUCwpy8NhUa2B5SyxYuoAJPAdtWm8dBYNw2xRLc6lK7F5t7cBye95H98B_lyZqeMQAj2p5w4xdxdps2HY7dpyEvNsiN2O_qugQSxzHHV-9NeBSZe0xHoD5",
                "Accept": "application/json"
            },
            "params": {},
            "retry": true,
            "responseType": "json",
            "retryConfig": {
                "currentRetryAttempt": 0,
                "retry": 3,
                "httpMethodsToRetry": [
                    "GET",
                    "HEAD",
                    "PUT",
                    "OPTIONS",
                    "DELETE"
                ],
                "noResponseRetries": 2,
                "statusCodesToRetry": [
                    [
                        100,
                        199
                    ],
                    [
                        429,
                        429
                    ],
                    [
                        500,
                        599
                    ]
                ]
            }
        },
        "data": {
            "error": {
                "errors": [
                    {
                        "domain": "global",
                        "reason": "notFound",
                        "message": "Not Found"
                    }
                ],
                "code": 404,
                "message": "Not Found"
            }
        },
        "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, max-age=0",
            "connection": "close",
            "content-encoding": "gzip",
            "content-security-policy": "frame-ancestors 'self'",
            "content-type": "application/json; charset=UTF-8",
            "date": "Thu, 11 Jun 2020 17:39:49 GMT",
            "expires": "Thu, 11 Jun 2020 17:39:49 GMT",
            "server": "GSE",
            "transfer-encoding": "chunked",
            "vary": "Origin, X-Origin",
            "x-content-type-options": "nosniff",
            "x-frame-options": "SAMEORIGIN",
            "x-xss-protection": "1; mode=block"
        },
        "status": 404,
        "statusText": "Not Found",
        "request": {
            "responseURL": "https://www.googleapis.com/calendar/v3/calendars/conncoll.edu_023hs5hct41vhhibamjbasdkbs%40group.calendar.google.com/events/irudvea992rumvho9eosunifq8"
        }
    },
    "config": {
        "url": "https://www.googleapis.com/calendar/v3/calendars/conncoll.edu_023hs5hct41vhhibamjbasdkbs%40group.calendar.google.com/events/irudvea992rumvho9eosunifq8",
        "method": "GET",
        "userAgentDirectives": [
            {
                "product": "google-api-nodejs-client",
                "version": "4.3.0",
                "comment": "gzip"
            }
        ],
        "headers": {
            "x-goog-api-client": "gdcl/4.3.0 gl-node/12.16.3 auth/6.0.1",
            "Accept-Encoding": "gzip",
            "User-Agent": "google-api-nodejs-client/4.3.0 (gzip)",
            "Authorization": "Bearer ya29.c.KpMBzgdYwb6AVurs1gP9fDRw4DMA1ys6ux77JueidiXXeloVDj0vw_hrAcu-souTl28QTrBIAYgz8OFqu7PUCwpy8NhUa2B5SyxYuoAJPAdtWm8dBYNw2xRLc6lK7F5t7cBye95H98B_lyZqeMQAj2p5w4xdxdps2HY7dpyEvNsiN2O_qugQSxzHHV-9NeBSZe0xHoD5",
            "Accept": "application/json"
        },
        "params": {},
        "retry": true,
        "responseType": "json",
        "retryConfig": {
            "currentRetryAttempt": 0,
            "retry": 3,
            "httpMethodsToRetry": [
                "GET",
                "HEAD",
                "PUT",
                "OPTIONS",
                "DELETE"
            ],
            "noResponseRetries": 2,
            "statusCodesToRetry": [
                [
                    100,
                    199
                ],
                [
                    429,
                    429
                ],
                [
                    500,
                    599
                ]
            ]
        }
    },
    "errors": [
        {
            "domain": "global",
            "reason": "notFound",
            "message": "Not Found"
        }
    ],
    "stack": [
        "Error: Not Found",
        "    at Gaxios._request (/var/task/node_modules/gaxios/build/src/gaxios.js:85:23)",
        "    at processTicksAndRejections (internal/process/task_queues.js:97:5)",
        "    at async JWT.requestAsync (/var/task/node_modules/google-auth-library/build/src/auth/oauth2client.js:342:22)",
        "    at async Runtime.exports.handler (/var/task/index.js:59:26)"
    ]
}

API Explorer with same CalendarId and EventId returns 200:

{
 "kind": "calendar#event",
 "etag": "\"3179827035790000\"",
 "id": "irudvea992rumvho9eosunifq8",
 "status": "confirmed",
 "htmlLink": "https://www.google.com/calendar/event?eid=aXJ1ZHZlYTk5MnJ1bXZobzllb3N1bmlmcThfMjAyMDA1MThUMTUwMDAwWiBjb25uY29sbC5lZHVfMDIzaHM1aGN0NDF2aGhpYmFtamJhc2RrYnNAZw",
 "created": "2020-02-16T19:15:21.000Z",
 "updated": "2020-05-19T18:38:37.933Z",
 "summary": "Lunch",
 "creator": {
  "email": "cw@conncoll.edu"
 },
 "organizer": {
  "email": "conncoll.edu_023hs5hct41vhhibamjbasdkbs@group.calendar.google.com",
  "displayName": "Harris Hours",
  "self": true
 },
 "start": {
  "dateTime": "2020-05-18T11:00:00-04:00",
  "timeZone": "America/New_York"
 },
 "end": {
  "dateTime": "2020-05-18T14:00:00-04:00",
  "timeZone": "America/New_York"
 },
 "recurrence": [
  "RRULE:FREQ=WEEKLY;WKST=SU;UNTIL=20200823;BYDAY=FR,MO,SA,TH,TU,WE"
 ],
 "iCalUID": "irudvea992rumvho9eosunifq8@google.com",
 "sequence": 1,
 "reminders": {
  "useDefault": false
 }
}

@JustinBeckwith
Copy link
Contributor

Ok this is getting weird. Could I trouble you to try the code I posted above, with the latest googleapis and @google-cloud/local-auth modules?

@atilling
Copy link
Author

Ran Sample code with 52.1.0
$ node server.js (node:49666) UnhandledPromiseRejectionWarning: Error: Not Found at Gaxios._request (/Users/atilling/Desktop/eventy/node_modules/gaxios/build/src/gaxios.js:85:23) at processTicksAndRejections (internal/process/task_queues.js:97:5) at async OAuth2Client.requestAsync (/Users/atilling/Desktop/eventy/node_modules/google-auth-library/build/src/auth/oauth2client.js:342:22) at async main (/Users/atilling/Desktop/eventy/server.js:12:15) (node:49666) 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:49666) [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.

@atilling
Copy link
Author

I ran it exactly as posted. I'll rerun shortly with cal and event ids i as trying to query

@atilling
Copy link
Author

Using my calendarId and eventId I am getting a result using the provided code.
Is it possible it is an issue with OAuth2 vs a service account?

@atilling
Copy link
Author

atilling commented Jun 12, 2020

This is the code I'm using that is failing

'use strict'
const privatekey = require("./camelwebKey.json");
const {google} = require('./node_modules/googleapis/build/src');
let message;
let calId;
let eventId;
let eventDate;

exports.handler = async (event) => {
    try{
        calId = "conncoll.edu_ungnu8i9cf8ntcrm2vtho3ums0@group.calendar.google.com";
        if(event && event.locationID){
            if (event['locationID'] == 'Harris'){
                calId = "conncoll.edu_023hs5hct41vhhibamjbasdkbs@group.calendar.google.com";
            } 
        }if(event && event.eventID){
            eventId = event['eventID'];
            eventDate =  eventId.substring(eventId.indexOf('|')+1,eventId.indexOf('|')+9);
            eventId = eventId.substring(0,eventId.indexOf('@'));
        }
        console.log ("CalId: "+calId);
        console.log ("EventId: "+eventId);
        console.log ("EventDate: "+eventDate);
        // configure a JWT auth client
        let jwtClient = new google.auth.JWT(
            privatekey.client_email,
            null,
            privatekey.private_key,
            ['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.events']);
        //authenticate request
        jwtClient.authorize(function (err, tokens) {
            if (err) {
                console.log(err);
                return;
            } else {
                console.log("Successfully connected!");
            }
        });
        const cal = google.calendar('v3');
        let folderList =[];
        let fconf = {};
        fconf.auth = jwtClient;
        fconf.calendarId = calId;
        fconf.eventId = eventId;
        const calEvent = await cal.events.get(fconf);
        console.log (calEvent);
        message = calEvent.data;
        
    } catch (err) {
        console.log(err);
        return err;
    }
   return message
};

@JustinBeckwith JustinBeckwith added type: question Request for information or clarification. Not an issue. and removed needs more info This issue needs more information from the customer to proceed. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Jun 19, 2020
@JustinBeckwith
Copy link
Contributor

Ah! Let's focus on this right here:
#2229 (comment)

I don't have a service account with access to a calendar on hand, so I have to try this blind 😆 Can you give something like this a shot?

const path = require('path');
const {google} = require('googleapis');

async function main() {
  const auth = new google.auth.JWT({
    scopes: ['https://www.googleapis.com/auth/calendar'],
    keyFile: path.resolve('../keys/jwt.keys.json'),
  });
  google.options({auth});
  const calendar = google.calendar('v3');
  const res = await calendar.events.get({
    calendarId: '<YOUR_CALENDAR_ID',
    eventId: 'YOUR_EVENT_ID',
  });
  console.log(res.data);
}
main();

I'm trying to distill this down to the minimum code to reproduce things :)

@JustinBeckwith JustinBeckwith added needs more info This issue needs more information from the customer to proceed. and removed priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jun 21, 2020
@fhinkel
Copy link
Contributor

fhinkel commented Dec 7, 2020

Greetings, we're closing this due to inactivity. Please let us know if the issue needs to be reopened.

@fhinkel fhinkel closed this as completed Dec 7, 2020
@fhinkel fhinkel assigned fhinkel and unassigned atilling Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: calendar Issues related to the Calendar API API. needs more info This issue needs more information from the customer to proceed. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

4 participants