Missing endtime whie inserting to calendar event - google-calendar-api

while trying to insert and event i continously getting the same error although i try to use different time zone and even copy pasted the the code snippet provided Events:insert.
The error i am getting is :
<HttpError 400 when requesting https://www.googleapis.com/calendar/v3/calendars/primary/events?alt=json returned "Missing end time.". Details: "Missing end time.">
The code i am using to create the event is :
event = {
'summary': data['summary'],
'description': data['description'],
'start': {
'dateTime': data['start_time'],
'timeZone': 'ASIA/KOLKATA',
},
'end': {
'dateTime': data['end_time'],
'timeZone': 'ASIA/KOLKATA',
},
'recurrence': [
'RRULE:FREQ=DAILY;COUNT=2'
],
'attendees': [
{'email': 'moinkhan8439#gmail.com'},
{'email': 'zainkhanjune#gmail.com'},
],
'reminders': {
'useDefault': False,
'overrides': [
{'method': 'email', 'minutes': 24 * 60},
{'method': 'popup', 'minutes': 10},
],
}
}
created_event = service.events().insert(calendarId='primary', body=event).execute()
I tried converting to RFC3339 but same error .
Note - i am getting data from a POST request through a serializer.

This error occur when we dont pass the correct format in the body section of the insert fucntion.
service.events().insert(calendarId='primary',sendNotifications=True, body=event).execute()
I found out that i was passing the datetime object into datetime keyword for event whereas we have to first convert the datetime into standard RFC339 as specififed under authorization section here
and then convert it to string to be passed into event body.
To convert Django models.datetime object into RFC3339 string do this:
str(date.isoformat('T'))

Related

Firestore Pagination : how to set Cursor for startAt using Rest Api

I'm using firebase firestore using Rest API to get data limited by 5 documents only, ordered by a field called LikesCount.
When I want to fetch the next 5 documents I have to use startAt and pass the LikesCount value of the last document from the first 5 documents.
But in this way, it will fetch wrong data when there is another document with the same LikesCount value So I tried and searched a lot about how to pass the last Document id in addition to the LikesCount value But all of them did not work In addition, I tested the pagination using the Web SDK and it was working correctly because you can pass the document snapshot easily, but what does the document snapshot object include? So that we can understand the structure of the Cursor and apply it to the REST API.
I tried to use this method to pass the Document ID as referenceValue
{
"structuredQuery": {
"from": [{
"collectionId": "Users"
}],
"where": {
"compositeFilter": {
"op": "AND",
"filters": []
}
},
"orderBy": [{
"field": {
"fieldPath": "LikesCount"
},
"direction": "DESCENDING"
}],
"startAt":
{ "values": [
{
"integerValue": "6"
},
{
"referenceValue": "projects/myprojectid/databases/(default)/documents/Posts/xEvmJ1LLHwTKVREQfXtX"
}
],
"before": false
},
"limit":5
}
}
But an error will occur : Cursor has too many values.
also, I tried to pass only the referenceValue and it still did not return the correct 5 documents.
Thanks in advance :)
Your orderBy() has 1 field (LikesCount) but your startAt() has 2 fields. I suspect that is the reason for the error message?
Passing the integerValue won't work. If there are 13 results with the value 6, then each time you make the above call you'd get the same first 5 results.
When you say:
I tried only passing the referenceValue and still did not get the correct 5 documents
what documents are you getting? What documents were you expecting to get?

Is it possible to manipulate the dimension name within the Google Analytics API response in the query itself

Here is a sample query that I created to fetch Google Analytics data:
response = service.reports().batchGet(
body={
'reportRequests': [
{
'viewId': 'xxxx',
'dateRanges': [{'startDate': '2021-01-14', 'endDate': '2021-01-15'}],
'metrics': [
{'expression': 'ga:pageViews'},
{'expression': 'ga:sessions'},
{'expression': 'ga:itemRevenue'},
{'expression': 'ga:hits'},
{'expression': 'ga:sessionDuration'},
],
# Get Pages
'dimensions': [
{"name": "ga:clientId"},
{"name": "ga:pagePath"},
{"name": "ga:dateHourMinute"},
{"name": "ga:shoppingStage"},
{"name": "ga:source"},
{"name": "ga:campaign"},
],
# Filter by condition
"filtersExpression": "ga:clientId==yyyy.zzzz",
'orderBys': [{"fieldName": "ga:dateHourMinute", "sortOrder": "DESCENDING"}],
'pageSize': 500
}]
}
).execute()
Sample response:
{'dimensions': ['yyyy.zzzz',
'/products/pants-green?variant=456456456',
'202101142347',
'ALL_VISITS',
'newsletter',
'2021_01-pre-sale',
'282'],
'metrics': [{'values': ['0',
'0',
'0.0',
'1',
'0.0']}]},
Is it possible to define alternate naming for the dimensions in the response within the query itself, e.g.
strip the variant part from the page path with regex,
change the wording for "ga:shoppingStage" from ALL_VISITS to something else?
Or is this something which needs to be done in post-processing?
The dimensions and metrics are standard within Google analytics. The response returned to you from the API is simply the name of the dimensions and metrics from the API.
Even if you have your own custom dimensiosn and metrics set up the API is still just going to return it with the name ga:dimensionXX
If you want to change the names your going to have to do that locally after the data is returned to you.

Why aren't updates to my mongodb query NOT always reflecting?

I have a Sessions.get() in my MongoDB query. This means the displayed collection depends on the Sessions.get() value. To give you a clearer image of what I mean, find below what my query looks like:
Template.paymentB2C.onCreated( function(){
Session.set('pendingFilter', [ "Pending", "Failed", "Success" ]);
});
.
Template.paymentB2C.helpers({
'showTransactions': function(){
var transactions = paymentDetails.find({
paymentStatus:{$in: Session.get('Filter')}
}).fetch();
return transactions;
}
});
The above code displays a list of transactions. The displayed list of transactions varies in types of transactions suggesting: Failed, Successful, to Pending transactions as seen more accurately below:
0:
payersName: "Sa Acea"
paymentStatus: "Success"
_id: "D3gY4BoR2tvxdK4xv"
1:
payersName: "Paul Acea"
paymentStatus: "Pending"
_id: "ajCjYbLaDP7x4iAFK"
2:
payersName: "Simon Bolton"
paymentStatus: "Success"
_id: "K4d6wDrjRRdSyCkhW"
I, therefore, use the Filter Session values as a Filter to dictate what types of transactions to display.
I am able to interchange between the three types of Filters via the below events. Find below the code.
Template.paymentB2C.events({
'click .ShowFailedTransactions' (event, instance) {
event.preventDefault();
Session.set('Filter', [ "Failed" ]);
},
'click .ShowSuccessfulTransactions' (event, instance) {
event.preventDefault();
Session.set('Filter', [ "Success" ]);
},
'click .ShowPendingTransactions' (event, instance) {
event.preventDefault();
Session.set('Filter', [ "Pending" ]);
},
});
Note that there isn't a Failed transaction type in the collection. So I find it very strange that whenever I choose the Failed filter 'click .ShowFailedTransactions' expecting the desired effect to be a blank empty page, the page fails to update and continues to the show the results of the previous query, as if I never clicked 'click .ShowFailedTransactions'.
I thought perhaps the Session.set('Filter', [ "Failed" ]) in the 'click .ShowFailedTransactions' function wasnt working, so I added a console.log(); to print out the Filter Session value as seen below:
'click .ShowFailedTransactions' (event, instance) {
event.preventDefault();
Session.set('Filter', [ "Failed" ]);
var displaySession = Session.get('Filter');
console.log("Filter Value is: " +displaySession );
},
The above code yields Filter Value is: Failed in the browser console, suggesting that the Filter session value gets updated as expected.
I am confused, to why the page will not respond/update to this.
Kindly help suggest a solution for this issue.
The problem in your code is the fetch, it's not reactive! The good news is that you don't need it. Try this:
Template.paymentB2C.helpers({
'showTransactions': function(){
return paymentDetails.find({paymentStatus: {$in: Session.get('Filter')}});
}
});

What is the proper way to use the `Sequelize.fn` method to format a SQLite3 datetime?

I'm experimenting with Sequelize.js using both a MySQL and a SQLite3 database and displaying the data in JSON format in the console. With MySQL, the Sequelize.fn function enables me to control the format of the createdAt and updatedAt fields like this:
[Sequelize.fn('date_format', Sequelize.col('updatedAt'), '%m-%d-%Y %H:%i:%s'), 'updatedAt']
For example:
Article.findAll({
attributes: [
'id',
'title',
'body',
[Sequelize.fn('date_format', Sequelize.col('createdAt'), '%m-%d-%Y %H:%i:%s'), 'createdAt'],
[Sequelize.fn('date_format', Sequelize.col('updatedAt'), '%m-%d-%Y %H:%i:%s'), 'updatedAt']
]
})
.then(tasks => {
console.log(JSON.stringify(tasks, null, 2))
})
returns this:
{
"id": 27,
"title": "This is a test title",
"body": "The main body of the article appears here.",
"createdAt": "05-28-2017 23:41:42",
"updatedAt": "05-28-2017 23:41:42"
}
SQLite, however, does not recognize the date_format function and throws an error:
Unhandled rejection SequelizeDatabaseError: SQLITE_ERROR: no such function: date_format
Research suggests that the correct SQLite function is strftime, but although no error message appears, the output is null. For example,
[Sequelize.fn('strftime', Sequelize.col('updatedAt'), '%m-%d-%Y %H:%i:%s'), 'updatedAt']
results in
{
"id": 42,
"title": "Hello world!",
"body": "This is stored in SQLite!",
"createdAt": "2017-05-28T23:19:41.738Z",
"updatedAt": null
}
Can anyone point me in the right direction?
I had the same problem. You were almost there. Only the parameters to Sequelize.fn were in the wrong order.
with
[Sequelize.fn('strftime', '%m-%d-%Y %H:%i:%s', Sequelize.col('updatedAt')), 'updatedAt']
your date should be properly formatted.
Thanks for pointing me in the right direction!

Fullcalendar with JSON feed returning eventSource in extended form

I'm using the excellent fullcalendar by arshaw with Angular UI and right now I'm having a problem with eventSource objects in extended form not rendering when fetched as JSON feeds.
The data is fetched using the following code in the controller:
$scope.events = [
'/api/v1/users/104/events?format=cal&type=9',
'/api/v1/users/104/events?format=cal&type=10'
];
$scope.eventSources = $scope.events;
When the JSON feed returns an array with event objects it actually works:
// returned by - /api/v1/users/104/events?format=cal&type=9
[
{
url: "/#/events/86893",
start: "2013-03-15",
title: ": Event - 86893"
},
{
url: "/#/events/31348",
start: "2013-03-27T09:30Z",
title: "Event - 31348"
}
],
// returned by - /api/v1/users/104/events?format=cal&type=10
[
{
url: "/#/events/86899",
start: "2013-03-25",
title: ": Event - 86899"
},
{
url: "/#/events/31349",
start: "2013-03-17T09:30Z",
title: "Event - 31349"
}
]
However I would like to specify some options along with the event data, for example different colors for different JSON feeds. Hence I settled for the API to return the event source in its extended form . This is what it API returns.
// returned by - /api/v1/users/104/events?format=cal&type=9
{
events: [
{
url: "/#/events/86893",
start: "2013-03-15",
title: "Event - 86893"
},
{
url: "/#/events/31348",
start: "2013-03-27T09:30Z",
title: "Event - 31348"
}
],
color: "#ff9900",
allDayDefault: false,
ignoreTimezone: true
},
// returned by - /api/v1/users/104/events?format=cal&type=10
{
events: [
{
url: "/#/events/86899",
start: "2013-03-25",
title: "Event - 86899"
},
{
url: "/#/events/31349",
start: "2013-03-17T09:30Z",
title: "Event - 31349"
}
],
color: "#3366FF",
allDayDefault: false,
ignoreTimezone: true
}
Unfortunately this format isn't rendered when fetched as JSON. When fetching the extended format I changed the eventSources assignment somewhat to look like this:
$scope.eventSources = [ $scope.events ];
If I cut and paste the raw JSON response (with the event source in its extended form) from the API straight into the eventSources method it works. Isn't it possible to consume the event source in extended form when it is returned as a JSON feed?
Could it be that the eventSource being returned from the API is not where the extended form options should be used, but rather in the event functions used as the eventSource's.
The documentation states that the extended form should be used inside of the Json object used to call the API.
http://arshaw.com/fullcalendar/docs/event_data/events_json_feed/
If the API was too return the extra options for the events, then it would need to set each one individually.
Currently in this post, The only place I see where the extended options are called is from the returned api data.
I think this should be the other way around. And the calendar should know about the extended form before it even requests the data at all. This would mean the server will not need to return any extra options and the calendar will organize the event objects by feed and extended options.
If you could post a plunk, then we could nail this.

Resources