Google Calendar API Freebusy query returns "notFound" error - google-calendar-api

I'm trying to learn how to use this query; I created an API key and used Postman to
Post https://www.googleapis.com/calendar/v3/freeBusy?key="THE_API_KEY"
with this request body:
{
"timeMin": "2022-11-16T00:00:31-00:00",
"timeMax": "2022-11-16T14:00:00-00:00",
"groupExpansionMax": 100,
"calendarExpansionMax": 50,
"items": [
{
"id": "MY_OWN_GMAIL_ADDRESS"
},
{
"id": "OTHER_GMAIL_ADDRESS"
}
]
}
and got this response:
{
"kind": "calendar#freeBusy",
"timeMin": "2022-11-16T00:00:31.000Z",
"timeMax": "2022-11-16T14:00:00.000Z",
"calendars": {
"MY_OWN_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
},
"OTHER_GMAIL_ADDRESS": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
}
}
}
What am I missing?

The Freebusy: query returns information about weither or not there is an event at the time of the request.
This method does not require authorization when being used against a public google calendar. There are a number of such calendars the holiday calendars are all public. You could also set your own calendar to public if you wish and then you would be able to use use an api key to access it.
API keys give you access to public methods only.
In order to access private user data. You need to be authorized using oauth2 with one of the following scopes.
If you do not have access to a calendar then it will return not found as you cant see it so your not going to be able to find it.
The solution i your case to fix your issue would be to either set the calendar to public and continue to use the api key. You will only be able to preform read actions against the calendar.
Or to switch to using oauth2 and send an authorization header with a bearer token.

Your post didnt include the Authorization header. Did you include it in your Postman Request?
Your need to send your Access Token as a Bearer Token in the Authorization Header
You can see an example for a request here:
https://developers.google.com/calendar/api/v3/reference/freebusy/query?apix=true#try-it

Related

Firebase short dynamic link authentication

I am trying to create short dynamic link using Firebase REST API but I am getting 401 error every time when I use API key from project settings site:
This is how my request body looks like:
{
"dynamicLinkInfo": {
"domainUriPrefix": "https://xxxx.page.link",
"link": "https://xxxx.page.link",
"androidInfo": {
"androidPackageName": "com.example.android"
},
"iosInfo": {
"iosBundleId": "com.example.ios"
}
}
}
https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=xxxxxx
What I'm doing wrong? I have Deeplink service enabled. I am out of ideas.
EDIT 1.
This is how response looks like:
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED"
}
}

First request to a webhook

To create a webhook, it has to pass the following validation:
Receive a GET request onto the webhook URL and read a specific "challenge" field from the query.
Send this field back to where the request comes.
Can this be implemented in an Integromat app?
Yes, you can use the verification directive for this purpose.
The code would look something like this:
{
"verification": {
"condition": "{{if(query.challenge, true, false)}}",
"respond": {
"status": 200,
"type": "json",
"body": {
"challenge": "{{query.challenge}}"
}
}
},
"response": {
"output": "{{body}}"
}
}
It's up to you to specify the verification condition so that the platform will be able to tell if the incoming message is a verification request or a regular webhook payload.

Google Analytics Reporting API - Get Activity with User ID

I can't get User Activity from the Google Analytics Reporting API (v4) using a User ID.
Client ID (in a different, non-User ID view) works, however.
Am I missing something?
--
For Client ID
I go here in my Google Analytics web interface:
https://analytics.google.com/analytics/web/#/report/visitors-user-activity/a45743608w76484324p79062844/_u.date00=20190327&_u.date01=20190402&_r.userId=1142688158.1525244974
I get user activity details as expected:
--
I call the following:
POST https://analyticsreporting.googleapis.com/v4/userActivity:search?key={YOUR_API_KEY}
{
"viewId": "79062844",
"dateRange": {
"startDate": "2019-03-27",
"endDate": "2019-04-02"
},
"user": {
"type": "CLIENT_ID",
"userId": "1142688158.1525244974"
}
}
I get the expected response:
{
"sessions": [
…
],
"totalRows": 14,
"sampleRate": 1
}
--
For User ID
I go here in my Google Analytics web interface:
https://analytics.google.com/analytics/web/#/report/visitors-user-activity/a45743608w76484324p185098721/_u.date00=20190327&_u.date01=20190402&_r.userId=Not%20Logged%20In-
I get user activity details as expected:
--
I call the following:
POST https://analyticsreporting.googleapis.com/v4/userActivity:search?key={YOUR_API_KEY}
{
"viewId": "185098721",
"dateRange": {
"startDate": "2019-03-27",
"endDate": "2019-04-02"
},
"user": {
"type": "USER_ID",
"userId": "Not Logged In-"
}
}
I get an error instead:
{
"error": {
"code": 400,
"message": "USER_ID: Not Logged In- not found.",
"status": "INVALID_ARGUMENT"
}
}
--
I have tried different IDs, different dates, changing the type to CLIENT_ID, URL encoding the User ID, and User IDs with no spaces - no joy.
It seems this is indeed a bug which several others are also experiencing.
This bug can be +1'd and followed here:
https://issuetracker.google.com/issues/130161158
Edit: This has now been fixed.
From your URL, you are looking for an ID called Not%20Logged%20In- which is not a valid id. Its probably changing the id when you copy paste the URL.

How can I use googles "Interesting Calendars" with their v3 FreeBusy API?

When I attempt to use a calendar such as en.usa#holiday#group.v.calendar.google.com (Or anything with the ID ending in group.v.calendar.google.com) The FreeBusy API errors with:
"calendars": {
"en.usa#holiday#group.v.calendar.google.com": {
"errors": [
{
"domain": "global",
"reason": "notFound"
}
],
"busy": []
}
}
Making the same request but asking for another calendar succeeds.
The request I am making is reproducible in the Google API Docs at https://developers.google.com/calendar/v3/reference/freebusy/query
Where the request body is:
{
"timeMin": "2018-07-01T11:21:53.682-04:00",
"timeMax": "2018-08-25T11:21:53.682-04:00",
"items": [
{
"id": "en.usa#holiday#group.v.calendar.google.com"
}
],
"timeZone": "UTC"
}
I ruled out credentials being an issue; the same credentials work with this calendarId when it is used on the events API. This should also mean that the calendarId is valid.
The google account being used has this interesting calendar added to it. (Those events show up in the combined view)

How to safely test WooCommerce api key acces rights?

For an application I'm building I would like to test if I have both read and write access on the customerkey, customersecret combination I receive.
Is there a specific function which is the least disrupting for testing write access? Or is creating and removing a product the adviced way to go?
You can try to create a Tax Class with missing fields. You'll get a validation error if the consumer key has write permission, vs an authorization error if it doesn't.
{
"code": "rest_missing_callback_param",
"message": "Missing parameter(s): name",
"data": {
"status": 400,
"params": [
"name"
]
}
}
vs
{
"code": "woocommerce_rest_authentication_error",
"message": "The API key provided does not have write permissions.",
"data": {
"status": 401
}
}

Resources