How to update "Going? Yes/No/Maybe" in Google calendar via API? - google-calendar-api

I am using Google Calendar API to work with events. For example, someone create an event and invites me. So, at the bottom of the event's detail I have 3 options of "Going": YES/NO/MAYBE. My question is how can I answer this by API?
I tried to use an UPDATE request, but it will create a new version of the event in my own calendar instead.
calendar.events.update(
{
calendarId: "primary",
eventId: event.id,
resource: {
start: {
dateTime: event.start.dateTime,
},
end: {
dateTime: event.end.dateTime,
},
attendees: [
{
email: "myemail#gmail.com",
responseStatus: "accepted",
},
],
},
},
(err, response) => {
}
)

For example, how about using patch instead of update as follows?
Modified script:
calendar.events.patch(
{
calendarId: "primary",
eventId: event.id,
resource: {
attendees: [
{
email: "myemail#gmail.com",
responseStatus: "accepted",
},
],
},
},
(err, response) => {
}
)
Reference:
Events: patch

Related

Firestore: REST API call to runQueries

URL:https://firestore.googleapis.com/v1/{parent=projects//databases//documents}:runQuery
Request body:
{ structuredQuery:
{ from: [
{ collectionId: 'questions'
}
],
orderBy: [
{ field:
{ fieldPath: 'created'
}, direction: 'DESCENDING' }
], select: { fields:
[
{ fieldPath: 'id' },
{ fieldPath: 'details' },
{ fieldPath: 'question' },
{ fieldPath: 'votes' }
]
},
where: {
compositeFilter: {
filters: [
{ fieldFilter: {
field: {
fieldPath: 'author'
},
op: 'EQUAL',
value: {
stringValue: "henry"
}
}
}
], op: 'AND'
}
},
limit: 4
}
}
What error do I get?
[{
"readTime": "2022-12-26T12:46:55.107240Z"
}]
the response isn't returning the expected results
What am I trying to do?
Fetch the given field from the collection: "questions" where the "author" matches "henry"
The documentation is available and it looks pretty straighforward.
Making REST calls
All REST API endpoints exist under the base URL https://firestore.googleapis.com/v1/.
To create a path to a document with the ID LA in the collection
cities under the project YOUR_PROJECT_ID you would use the
following structure.
/projects/YOUR_PROJECT_ID/databases/(default)/documents/cities/LA
To interact with this path, combine it with the base API URL.
https://firestore.googleapis.com/v1/projects/YOUR_PROJECT_ID/databases/(default)/documents/cities/LA
The best way to begin experimenting with the REST API is to use
the API Explorer, which automatically generates Google Identity OAuth
2.0 tokens and allows you to examine the API.

Next.js header does not work on first load, only after refresh

I need to use SharedArrayBuffer for a specific page, so I put this in next.config.js:
async headers() {
return [
{
source: '/upload',
headers: [
{
key: 'Cross-Origin-Embedder-Policy',
value: 'require-corp',
},
{
key: 'Cross-Origin-Opener-Policy',
value: 'same-origin',
},
],
},
]
},
The problem is, this only works when I go to the page and I do a refresh.

I Couldn't change HTTP headers in a NextJS project

As explained in the NextJs documentation: https://nextjs.org/docs/api-reference/next.config.js/headers , it is possible to configure the HTTP headers of a page using the code below, however my code is not working.
Next Example:
module.exports = {
async headers() {
return [
{
source: '/about',
headers: [
{
key: 'x-custom-header',
value: 'my custom header value',
},
{
key: 'x-another-custom-header',
value: 'my other custom header value',
},
],
},
]
},
}
My Code:
module.exports = {
async headers() {
return [
{
source: '/about',
headers: [
{
key: 'cache-control',
value: 'max-age=31536000',
},
],
},
]
},
}

Implementing Push notification using Strongloop

I am trying to use strongloop loopback sdk 2.0. I tried to use the following code https://github.com/strongloop/loopback-component-push/tree/master/example/server which is loopback version 1.7.0. But when i try compile with version 2.0, it throws me error
Error: The data in model-config.json is in the unsupported 1.x format.
I had also tried as per the strong loop tutorial, but still it does not work. Anyone has suggestion or sample code on how to implement PUSH notification using loopback 2.0?
Create 4 models application, installation, notification, push
In common/models/application.json
{
"name": "push",
"plural": "Push",
"base": "Model",
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
In common/models/installation.json
{
"name": "installation",
"base": "Installation",
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
In common/models/notification.js
{
"name": "notification",
"base": "Notification",
"properties": {},
"validations": [],
"relations": {},
"acls": [
{
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW",
"property": "sendMessage"
}
],
"methods": []
}
In common/models/push.json
{
"name": "push",
"plural": "Push",
"base": "Model",
"properties": {},
"validations": [],
"relations": {},
"acls": [],
"methods": []
}
server/datasource.json
...
...
"push": {
"name": "push",
"connector": "loopback-component-push",
"installation": "installation",
"notification": "notification",
"application": "application"
}
In common/models/notification.js
module.exports = function(Notification) {
var badge = 1;
//DEFINING A PROPERTY IN NOTIFICATION FOR SENDING PUSH MESSAGE
Notification.sendMessage = function(message, registrationId, from, callback) {
var app = this.app;
from = from? from:'COMPANY_NAME';
sendMessage(app, message, registrationId, from, callback);
}//sendMessage Notification method..
//FUNCTION FOR SENDING PUSH MESSAGE..
var sendMessage = function(app, message, registrationId, from, callback){
var Application = app.models.application;
var PushModel = app.models.push;
var note = new Notification({
expirationInterval: 3600, // Expires 1 hour from now.
badge: badge++,
// sound: 'ping.aiff',
message: message,
messageFrom: from
});
PushModel.notifyById(registrationId, note, function (err) {
if (err) {
console.error('Cannot notify %j: %s', registrationId, err.stack);
return callback(err);
}
console.log('Pushing notification to %j', registrationId);
callback(null, []);
});
}//sendMessage function
//Now registering the method
Notification.remoteMethod(
'sendMessage',
{
accepts: [{arg: 'message', type: 'string', required:true},
{arg: 'registrationId', type: 'string', required:true},
{arg: 'from', type: 'string', required:true}],
description: "Sending message from notification.."
}
)
}//module.exports
Now inside server/ folder create a file push-service.js
module.exports = function(app) {
var Notification = app.models.notification;
var Application = app.models.application;
var PushModel = app.models.push;
function startPushServer() {
PushModel.on('error', function(err) {
console.error('Push Notification error: ', err.stack);
});
// Pre-register an application that is ready to be used for testing.
// You should tweak config options in ./config.js
var loopbackApp = {
id: 'loopback-push-application',
userId: 'strongloop',
name: config.appName,
description: 'loopback Push Notification Service',
pushSettings: {
apns: {
certData: "APPLE CERT. DATA",
keyData: "APPLE KEY DATA",
pushOptions: {
// Extra options can go here for APN
},
feedbackOptions: {
batchFeedback: true,
interval: 300
}
},
gcm: {
serverApiKey: "PASTE YOUR GOOGLE GCM KEY HERE"
}
}
};
updateOrCreateApp(function(err, appModel) {
if (err) {
throw err;
}
console.log('Application id: %j', appModel.id);
});
function updateOrCreateApp(cb) {
Application.findOne({
where: {
id: loopbackApp.id
}
},
function(err, result) {
if (err) cb(err);
if (result) {
delete loopbackApp.id;
result.updateAttributes(loopbackApp, cb);
} else {
return registerApp(cb);
}
});
} //updateOrCreate function
Application.beforeSave = function(next) {
if (this.name === loopbackApp.name) {
this.id = 'loopback-push-application';
}
next();
};
Application.register(
loopbackApp.userId,
loopbackApp.name, {
description: loopbackApp.description,
pushSettings: loopbackApp.pushSettings
},
function(err, app) {
if (err) {
return cb(err);
}
return cb(null, app);
}
);
} //register App
} //startPushServer
startPushServer();
};
Now finally in server.js
....
....
//Adding push service to the backend..
require('./push-service')(app);
....
Now run the loopback server open api explorer and go to NOTIFICATION->SendMessage method and type any message and it will send push notification on connected devices.
NOTE: You also need to configure push services from android/iphone to enable sending push application. For detail check loopback documentation.
Please check out this example - https://github.com/strongloop/loopback-component-push/tree/master/example/server-2.0

ASP.NET WebAPI KendoUI, can't update, create, delete data, 405 Method not allowed

I'm using ASP.NET WebApi in conjunction with KendoUI. Json is successfully displayed in the grid, so GET works. But I can't UPDATE, CREATE or DELETE data. Any idea what I am missing? Even in the Telerik forum I couldn't find anything that points me into the right direction. And I also looked through their examples. Must I somehow pass values to PUT, POST, and DELETE?
<script type="text/javascript">
var remoteDataSource = new kendo.data.DataSource({
transport: {
read: { url: '/api/NorthwindProductWebApi', dataType: "json", type: "GET" },
update: { url: '/api/NorthwindProductWebApi', dataType: "json", type: "PUT"},
create: { url: '/api/NorthwindProductWebApi', dataType: "json", type: "POST" },
destroy: { url: '/api/NorthwindProductWebApi', dataType: "json", type: "DELETE" },
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) }
;
}
}
},
pageSize: 20,
batch: true,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { type: "number" },
ProductName: { type: "string" },
SupplierID: { type: "number" },
CategoryID: { type: "number" },
QuantityPerUnit: { type: "string" },
UnitPrice: { type: "string" },
UnitsInStock: { type: "number" },
UnitsOnOrder: { type: "number" },
ReorderLevel: { type: "number" },
Discontinued: { type: "string" }
}
}
}
});
$('#grid').kendoGrid({
dataSource: remoteDataSource,
heigth: 100,
groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
toolbar: ["create"],
columns: [{
command: ["edit", "destroy"], title: " ", width: "200px"
},
{
field: "ProductID",
title: "ProductID",
width: 200
}, {
field: "ProductName",
title: "ProductName",
width: 250
}, {
field: "SupplierID",
title: "SupplierID",
width: 200
}, {
field: "CategoryID",
title: "CategoryID",
width: 200
}, {
field: "QuantityPerUnit",
title: "QuantityPerUnit",
width: 200
}, {
field: "UnitPrice",
title: "UnitPrice",
width: 250
}, {
field: "UnitsInStock",
title: "UnitsInStock",
width: 200
}, {
field: "UnitsOnOrder",
title: "UnitsOnOrder",
width: 250
}, {
field: "ReorderLevel",
title: "ReorderLevel",
width: 200
}, {
field: "Discontinued",
title: "Discontinued",
width: 250
}],
editable: "popup",
save: function(){
this.refresh();
},
scrollable: true,
filterable: {
extra: false,
operators: {
string: {
startswith: "beginnt mit",
eq: "exakt",
neq: "enthält nicht"
},
number: {
//???contains: "contains",
eq: "exakt",
//???doesnotcontain: "Is not equal to"
}
},
}
});
</script>
Update:
Chrome gives me a 405 Method not allowed method on PUT and a 500 (Internal Server Error) on POST. Here is a snippet from the scaffold WebApi Controller and the chrome output, which is the same for both errors:
POST http://localhost:123/api/NorthwindProductWebApi 500 (Internal Server Error) jquery-1.10.2.js:8720
send jquery-1.10.2.js:8720
jQuery.extend.ajax jquery-1.10.2.js:8150
ct.extend.create kendo.all.min.js:11
(anonymous function) kendo.all.min.js:11
jQuery.extend.Deferred jquery-1.10.2.js:3274
lt.extend._promise kendo.all.min.js:11
lt.extend._send kendo.all.min.js:11
lt.extend.sync kendo.all.min.js:11
j.extend.saveRow kendo.all.min.js:23
(anonymous function) kendo.all.min.js:22
jQuery.event.dispatch jquery-1.10.2.js:5109
elemData.handle jquery-1.10.2.js:4780
// POST api/NorthwindProductWebApi
[ResponseType(typeof(Product))]
public IHttpActionResult PostProduct(Product product)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.Products.Add(product);
db.SaveChanges();
return CreatedAtRoute("DefaultApi", new { id = product.ProductID }, product);
}
Attempt to change the Url in the DataSource:
create: {
url: function(options) {
return '/api/NorthwindProductWebApi/PostProduct' + options.ProductID
},
type: "POST",
dataType: "json"
Normally you decorate your controller with
[HttpGet]
[HttpPost]
If you decided to use full set of REST request methods ,Get,Put,Delete,Post then you must handle them by decorating on the controller method to tell the compiler which method will be processing which type of request.
[HttpGet]
public ActionResult HelloWorld()
{}
[HttpPost]
public ActionResult HelloWorld(Model model)
{}
[HttpPut]
public ActionResult HelloWorld(Model model)
{}
[HttpDelete]
public ActionResult HelloWorld(int Id)
{}
For more information Link: PUT vs POST in REST
Ok, so, your controller is named NorthwindProductWebApiController and your POST method in the controller is named PostProduct. The solution is one of two choices. You can either rename PostProduct to Post - removing the Product part in the name, or change the url in your Kendo DataSource create definition to api/NorthwindProductWebApi/PostProduct.
Remember that ASP.NET WebApi is based on convention. You do not have to fully name your controller methods. Typically, the HTTP verb is sufficient. It knows which method to call based on the verb and number of arguments. If you do however fully name the method, you must fully name it in the URL.

Resources