Google Calendar API - Clear all events - google-calendar-api

I'm trying to clear all the events of a google calendar using the calendar ID.
https://developers.google.com/resources/api-libraries/documentation/calendar/v3/python/latest/calendar_v3.calendars.html#clear
Attempting it, gives a "400 Bad Request" response from either Python or a simple curl call using the Google API Explorer:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Value"
}
],
"code": 400,
"message": "Invalid Value"
}
}
From either the API explorer or the python API I'm providing only the calendar ID of the corresponding (non-primary) calendar I want to delete.
In Python:
service.calendars().clear(calendarId=<calid-found-in-calendarList().list()>).execute()
Which returns:
<HttpError 400 when requesting https://www.googleapis.com/calendar/v3/calendars/<calendar-id>4%40group.calendar.google.com/clear? returned "Invalid Value". Details: "[{'domain': 'global', 'reason': 'invalid', 'message': 'Invalid Value'}]">
Any idea what I'm doing wrong?

When I had tested the clear method of Calendars in Calendar API v3 before, I had experienced the same situation with you. When I used the value of primary, no error occurs. All events of the primary calendar are deleted. But, when I used the calendar ID except for the primary calendar, the same issue occurred.
When I saw the official document, it says Clears a primary calendar. This operation deletes all events associated with the primary calendar of an account.. But about calendarId in this method, it also says Calendar identifier. To retrieve calendar IDs call the calendarList.list method. If you want to access the primary calendar of the currently logged in user, use the "primary" keyword..
These documents consuse me. So, I checked this "clear" method at Discovery API. Ref It says as follows.
"clear": {
"parameters": {
"calendarId": {
"location": "path",
"required": true,
"type": "string",
"description": "Calendar identifier. To retrieve calendar IDs call the calendarList.list method. If you want to access the primary calendar of the currently logged in user, use the \"primary\" keyword."
}
},
"scopes": [
"https://www.googleapis.com/auth/calendar"
],
"httpMethod": "POST",
"id": "calendar.calendars.clear",
"description": "Clears a primary calendar. This operation deletes all events associated with the primary calendar of an account.",
"parameterOrder": [
"calendarId"
],
"path": "calendars/{calendarId}/clear"
},
From above document, I thought that the calendar ID can be retrieved by the calendarList.list method. But, this "clear" method might not be able to be used for the calendar except for the primary calendar.
And, when I saw the error message, when the calendar ID like ####group.calendar.google.com is used, the error of "message": "Invalid Value" occurs. But, when sample is used as the calendar ID, "message": "Not Found" is returned. It seems that the API might search the calendar. In this case, even when the URL encoding is used, the same issue occurs. From this situation, I thought that this might be a bug.
But, I'm not sure whether this is the current specification or a bug. So, I searched this situation at the issue tracker. But, unfortunately, I couldn't find the same issue. So how about reporting this at the Google issue tracker? Ref
Reference:
Calendars: clear

Something to add to this when I encountered the same issue. Seeing that clearing secondary calendars of events is not currently an option, you can outright delete the calendar and re-create it however, the downside to this is the change in the calendar id on re-creation.
Delete calendar documentation
Deletes a secondary calendar. Use calendars.clear for clearing all events on primary calendars.

Related

Linkedin Ads Reporting returning empty 'elements' array for a given campaign

I am trying to get some information about a specific LinkedIn campaign, but I'm getting an empty 'elements' array as response.
The catch is that the campaign has zero in all metrics when looking on the Campaign Manager. I think it was never actually veiculated, because even the cost is zero (and the status is COMPLETED).
My doubt is: should the array actually be empty, or be filled with zero on the values of the metrics and I'm messing up the requests?
This is what I'm doing:
First a GET request to see all campaigns that are associated with that Token:
GET https://api.linkedin.com/v2/adCampaignsV2?q=search
and this a part of the response:
...
"costType": "CPC",
"name": "Posts",
"offsiteDeliveryEnabled": true
"id": 128237464,
...
Then another GET request to see the info about that campaign:
GET https://api.linkedin.com/v2/adAnalyticsV2?q=analytics&pivot=CAMPAIGN&dateRange.start.day=25&dateRange.start.month=6&dateRange.start.year=2019&timeGranularity=MONTHLY&campaigns[0]=urn:li:sponsoredCampaign:128237464
But this is the response:
{
"elements": [],
"paging": {
"count": 10,
"start": 0,
"links": []
}
}
My app has the r_ads_reporting permission and Development tier on the Marketing Developer Platform.
I've also manually added the account ID of that company on the MDP Settings.
The problem was in the campaigns I used. After this I tested with some campaigns that had real ads and I got the expected response

Restore missing or deleted calendar

Working with one of my Google Apps users and a shared calendar he create suddenly disappeared. It was hidden (first thing we checked), but just gone. It is a number of steps to delete a calendar (for safety reasons) and it was certainly not deleted in this fashion.
Using the Google APIs Explorer for Calendar API v3 we do see a deleted calendar using calendar.calendarList.list when showDeleted is true. If we highlight that item in the JSON response the dropdown arrow on the top right of the item shows it can be used in calendar.calendarList.patch. Trying to remove the "deleted" flag results in a 404 resource not found. Copied the calendarId from the Patch JSON body up to the calendarId box, fields editor to show most all fields. Trying the same for calendar.calendars.patch we get the same result.
The OAuth scope is https://www.googleapis.com/auth/calendar. JSON body is
{
"kind": "calendar#calendarListEntry",
"etag": "\"XXXXXXXXXXXXXXXX\"",
"id": "XXXXXXXXXXXXXXXXXXXXXXXX#group.calendar.google.com",
"defaultReminders": [
],
"deleted": false
}
If a calendar is deleted from the CalendarList but you still know the id, you can add it back to the list with the insert endpoint.

Event attendee ID missing on Google Calendar Events list response

The Google Calendar specifies that it will return an array of Event resources that will also include:
attendees[].id (string) The attendee's Profile ID, if available. It
corresponds to theid field in the People collection of the Google+ API
However, when I invoke the Events:list API it returns me an attendee with the following properties only:
{
"email": "attendee.address#gmail.com",
"displayName": "Attendee Name",
"responseStatus": "accepted"
}
I would like to fetch more information (and namely the user avatar) for this user/attendee by invoking the Google+ API, however, without an ID I can't do much.
The endpoint that I am using to fetch events is https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events?${params} which I confirm is the latest API version.
Any thoughts on this issue would be much welcome!

Using webhooks with Google Analytics

I'm trying to integrate my CRM with Google Analytics to monitor lead changes (from lead to sell) and so on. As I understood, I need to use Google Measurement Protocol, to receive webhooks from CRM and translate it to Analytics Conversions.
But in fact, I don't really understand how to do it. I need to make some script, to translate webhook code to analytics, but where I need to place that script? Are there some templates? And so on.
So, If you know some tutorials/courses/freelancers to help me with intergrating webhooks with Analytics - I need your advice.
Example of webhook from CRM:
{
"leads": {
"status": {
"id": "25399013",
"name": "Lead title",
"old_status_id": "7039101",
"status_id": "142",
"price": "0",
"responsible_user_id": "102525",
"last_modified": "1413554372",
"modified_user_id": "102525",
"created_user_id": "102525",
"date_create": "1413554349",
"account_id": "7039099",
"custom_fields": [
{
"id": "427183",
"name": "Checkbox custom field",
"values": ["1"]
},
{
"id": "427271",
"name": "Date custom field",
"values": ["1412380800"]
},
{
"id": "1069602",
"name": "Checkbox custom field",
"values": ["0"]
},
{
"id": "427661",
"name": "Text custom field",
"values": ["Валера"]
},
{
"id": "1075272",
"name": "Date custom field",
"values": ["1413331200"]
}
]
}
}
}
"Webhook" is a fancy way of saying that your CRM can call a web based service whenever something interesting happens (i.e. the CRM can "hook" into a web based application). E.g. if a new lead is created you can call an url with the lead details as parameters.
Specifics depend on your CRM, but when you set up a webhook there should be a field to set a url; the script that evaluates the CRM data is located at the URL.
You have that big JSON thing as your example - No real way to tell without knowing your system, but I assume that is sent as request body. So in your script you evaluate the request body, extract the parameters you want to send to analytics (be mindful that you are not allowed to store personally identifiable information) and sent it via the measurement protocol as described in the documentation linked in the other answer.
Depending on the system you might even be able to call the measurement protocol without having a custom script in between (after all the measurement protocol is an url with a few parameters).
This is an awfully generic answer, but then the question is really broad.
I've done just this in my line of work.
You need to first decide your data model on how you would like the CRM data to look within Google Analytics. This could be just mapping Google Analytics' event category, event label, event action to your data, or perhpas using custom dimensions and metrics.
Then to make it most useful, you would like to be able to link the CRM activity of a customer to their online activity. You can do this if they login online. In that case, you can set the cid and/or uid of the user to your CRM id.
Then, if you send in a GA hit with the same cid/uid in your Measurement Protocol hit, you will link the online sessions with your offline CRM activity.
To make the actual record hit Google Analytics, you will need to program something that takes the CRM data and turns it into a Measurement Protocol hit, which is essentially just a URL with the correct parameters. Look here for reference: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference
An example could be: http://www.google-analytics.com/collect?v=1&tid=UA-123456-1&cid=5555&t=pageview&dp=%2FpageA
We usually have this as a seperate process, that fires when the CRM data is written to its database (the webhook in your example). If its a lot of data, you should probably implement checks to see if the hit was sucessful, and caching in case the service is not online - you have an optional parameter that gives you 4 hours leeway in sending data.
Hope this gets you at least started.

Google Analytics Query Custom Channel Grouping

I am trying to pull a Custom Channel Grouping for Transaction IDs from Google Analytics. The marketing group has defined a couple of custom Channel Groupings in GA and they want me to pull these fields. I can not find any documentation anywhere which discusses this. It's not a custom dimension and it's not a custom variable. Has anyone else had to do this? Is it possible or do I have to re-implement the rules outside of GA?
Short answer: this is not currently possible (as of June 2015) in the Google Analytics API.
The best workaround I have found is to rebuild the channel grouping in the logic of the API query. For example, if you have a channel group that is defined in your custom grouping as "campaign contains shopping AND source == google," you can write that into the filters line of the optArgs call to the API.
This doesn't strike me as a sustainable, maintainable practice, however -- if the custom grouping is changed, you need to go back and change your code separately -- but it's the best solution available at the moment.
Example code is Javascript:
The filter doesn't seem to work for ga:channelGrouping, so 'filters':'ga:channelGrouping=Direct', fails with the error:
{
"error": {
"errors": [{
"domain": "global",
"reason": "invalidParameter",
"message": "Invalid value 'ga:channelGrouping=Direct' for filters parameter."
}],
"code": 400,
"message": "Invalid value 'ga:channelGrouping=Direct' for filters parameter."
}
}
But you can get the ga:channelGrouping back as a dimension:
gapi.client.analytics.data.ga.get({
'ids': 'ga:' + profileId,
'start-date': 'yesterday',
'end-date': 'today',
'dimensions':'ga:channelGrouping,ga:date, ga:landingPagePath, ga:pagePath',
'metrics': 'ga:entrances',
'sort': '-ga:date',
})
so you get it in the data:
[
/*Channel grouping*/
"(Other)",
"20150730",
"blah",
"vlah",
"7"
]
At the moment I'm planning on filtering the channel grouping in my own code once I get the result back rather than trying to get Google to do this for me. Basically because Google doesn't seem to support this right now...

Resources