cannot read properties of undefined (reading 'reports') - youtube-analytics-api

I am trying to make a call to youtube analytics api but I get the following error:
Cannot read properties of undefined (reading 'reports')
function makeApiCall() {
return gapi.client.youtubeAnalytics.reports.query({
"ids": "channel==MINE",
"startDate": "2017-01-01",
"endDate": "2017-12-31",
"metrics": "views,estimatedMinutesWatched,averageViewDuration,averageViewPercentage,subscribersGained",
"dimensions": "day",
"sort": "day"
})
.then(function(response) {
// Handle the results here (response.result has the parsed body).
console.log("Response", response);
},
function(err) { console.error("Execute error", err); });
}
The application is successfully loaded and authorized. But cannot make the request. Any help is highly appreciated.

Related

GraphQL query result for object that does not exist

I have a GraphQL query that calls a REST service to get the return object. The query contains an Id parameter that is then passed to the service. However, the REST service can respond with http status 404 Not Found if an object with that Id does not exist. That seems like the right response.
How do you model a Not Found response in GraphQL?
Is there a way to inform the GQL caller that something does not exist?
Update
Some options I am considering:
Return null
Change the GrqlhQL Query to return a list of objects and return empty list of nothing is found
Return some kind of error object with an error code
but it is unclear if there is a recommended practice in GQL API design.
You might treat it as an error and handle it accordingly.
I recommend you to check the GraphQL spec, the paragraph about error handling.
I hope it contains exactly what you are looking for.
Basically, you should return whatever you could, and inform a client about potential problems in the "errors" field.
The example from the documentation:
Request:
{
hero(episode: $episode) {
name
heroFriends: friends {
id
name
}
}
}
Response:
{
"errors": [
{
"message": "Name for character with ID 1002 could not be fetched.",
"locations": [ { "line": 6, "column": 7 } ],
"path": [ "hero", "heroFriends", 1, "name" ]
}
],
"data": {
"hero": {
"name": "R2-D2",
"heroFriends": [
{
"id": "1000",
"name": "Luke Skywalker"
},
{
"id": "1002",
"name": null
},
{
"id": "1003",
"name": "Leia Organa"
}
]
}
}
}

Smart Home - Correct JSON to respond to EXECUTE when device is offline

When i try to execute a command and that the device is offline, Assistant still tell me that the command as been successfully be done.
I don't have this problem when it's a QUERY request, but with EXECUTE...
This is my returned JSON:
{
"requestId": "XXXXXX",
"payload": {
"commands": [
{
"ids": [123],
"status": "ERROR",
"errorCode": "deviceTurnedOff",
"online": false
}
]
}
}
I have also try this:
{
"requestId": "XXXXXX",
"payload": {
"commands": [
{
"ids": [123],
"status": "OFFLINE",
"errorCode": "deviceTurnedOff",
"online": false
}
]
}
}
I expect that when i try to do a command on an offline device, google assistant tell me that the device is not available, but i have a Ok, i turn the light on instead.
So if you have any idea, because i have checked my JSON response 1 million times and read the documentation many times but i can't find my mistake.
The documentation here is a bit confusing because the example shows the response payload for the QUERY intent.
The response payload for an EXECUTE intent is slightly different and is documented here.
The JSON using the correct reference the EXECUTE response payload will look like:
{
"requestId": "XXXXXX",
"payload": {
"commands": [{
"ids": ["123"],
"status": "OFFLINE",
"errorCode": "deviceTurnedOff"
}]
}
}
Note: deviceId should be a string, as noted in the EXECUTE Response payload details.
Quoting from the doc:
ids: Array. Required. Partner device IDs of the response

Google Analytics Multiple Date Ranges - NodeJS

How can I get a report using multiple date ranges, like the example listed below, using nodeJS client library?
It was taken from https://developers.google.com/analytics/devguides/reporting/core/v4/basics#multiple_date_ranges
POST https://analyticsreporting.googleapis.com/v4/reports:batchGet
{
"reportRequests":
[
{
"viewId": "XXXX",
"dateRanges": [
{"startDate": "2014-11-01", "endDate": "2014-11-30"},
{"startDate": "2014-10-01", "endDate": "2014-10-30"}
],
"metrics": [
{"expression": "ga:pageviews"},
{"expression": "ga:sessions"}
],
"dimensions": [{"name": "ga:pageTitle"}]
}
]
}
I tried this:
"dateRanges": [
{ "startDate": "2018-03-17", "endDate": "2018-03-24" },
{ "startDate": "14daysAgo", "endDate": "7daysAgo" }
]
And got the following error:
Missing required parameters: start-date, end-date
Thanks very much for the help!
UPDATE
I figured I was using the wrong function analytics.data.ga.get instead of analyticsreporting.reports.batchGet
But when I try this:
analyticsreporting.reports.batchGet({
"reportRequests": [
{
"viewId": req.params.profileId,
"dateRanges": [
{
"startDate": "2018-03-17",
"endDate": "2018-03-24"
},
{
"startDate": "14daysAgo",
"endDate": "7daysAgo"
}
],
"metrics": [
{
"expression": "ga:users"
}
]
}
]
}, function (err, results) {
if (err){
console.log('ERROR: ');
console.log(err.errors);
res.status(500).send(err.errors);
}
console.log(JSON.stringify(results));
res.send({results: results});
});
I get
message: 'Invalid JSON payload received. Unknown name "reportRequests[dateRanges][endDate]": Cannot bind query parameter. Field \'reportRequests[dateRanges][endDate]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "reportRequests[dateRanges][startDate]": Cannot bind query parameter. Field \'reportRequests[dateRanges][startDate]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "reportRequests[viewId]": Cannot bind query parameter. Field \'reportRequests[viewId]\' could not be found in request message.\nInvalid JSON payload received. Unknown name "reportRequests[metrics][expression]": Cannot bind query parameter. Field \'reportRequests[metrics][expression]\' could not be found in request message.',
What am I missing here?
Thanks!
For future reference
The reportsRequest object here needs to be inside of a resource object, as it's part of the post body as stated by JustinBeckwith at https://github.com/google/google-api-nodejs-client/issues/1085

Error Response with Google Smart Home (Thermostat)

I am unable to understand the syntax of Json for errors
I have tried
return {
"requestId": self.request_id,
"payload": {
"commands": [{
"ids": [self.device_id],
"status": "OFFLINE",
"errorCode": "deviceTurnedOff"
}]
}
}
and
return {
"requestId": self.request_id,
"payload": {
"errorCode": "authFailure",
"commands": [{
"devices": [{
"ids": [self.device_id],
"status": "ERROR",
"errorCode": "deviceTurnedOff"
}]
}]
}
}
and
return {
"requestId": self.request_id,
"payload": {
"errorCode": self.error_code
}
}
none of above syntax are working, most of the time google home says that your actions is performed but I am returning error Json there.
I have read google actions documentation but failed to understand.
I have come up with a few payloads and have managed to get them successfully triggering errors using the AoG simulator after consulting the docs.
Node.js snippet:
let resBody = {
requestId: request.requestId,
payload: {
"errorCode": "notSupported"
}
}
response.status(200).json(resBody);
Are you sure that the requestId is the same from the smart home request? How are you testing these errors?

Add event to calendar on SharePoint through REST API

I'm trying to add a calendar event to a SharePoint Calendar through REST API but i can't seems to find the relevant resources to achieve this.
If i understand correctly, the calendar in SharePoint is a List of events object, as such I should be able to add the event via ListItem object?
Sorry if this sounds wrong as I'm not familiar with SharePoint structure.
Thanks
This is the example for OAuth token Authentication but REST part is anyway like this.
var dataObj = {
"Subject": "Birthday Party"
"Body": {
"ContentType": "Text",
"Content": "Birthday Party for Cathy",
},
"Start": {
"dateTime": "2016-07-03T09:00:00Z",
"timeZone": "Asia/Tokyo"
},
"End": {
"dateTime": "2016-07-04T11:00:00Z",
"timeZone": "Asia/Tokyo"
},
"Location": {
"DisplayName": "Conference Room 1"
},
"ShowAs": "Busy",
"Attendees": [
{
"EmailAddress": { "Name": "Alex Darrow", "Address": "darrow.alex#company.com" },
"Type": "Required"
}
]
};
var url = "https://graph.microsoft.com/v1.0/me/events/";
var data = JSON.stringify(dataObj);
$.ajax({
url: url,
type: "POST",
data: data,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json;odata.metadata=full;odata.streaming=true");
XMLHttpRequest.setRequestHeader('Authorization', 'Bearer ' + accessToken);
XMLHttpRequest.setRequestHeader("content-type", "application/json;odata=verbose");
},
success: function (result, textStatus, jqXHR) {
//Success
},
error: function (data) {
//
}});