Not getting Authorization dialog for App Script accessing BigQuery Service - google-apps-script

I am trying to fix some App Scripts which use the BigQuery "Advanced Service" to install some BigQuery jobs. The first new script I ran popped a BigQuery authorization dialog, and everything worked fine, now running hourly. The second new script ran initially, but is now failing with:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
This began about 12 hours after the initial authorization, so it seems like something expired. But, I can't figure out how to trigger the authorization dialog to appear. Also, I expected an authorization would be required for each distinct function, yet the second one initially ran without asking for BigQuery permissions.
Additional Info:
Here is the .gs file I am executing:
function runQuery() {
var projectId = redacted;
var configuration = {
"query": {
"useQueryCache": false,
"destinationTable": {
"projectId": projectId,
"datasetId": redacted,
"tableId": redacted
},
"writeDisposition": "WRITE_TRUNCATE",
"createDisposition": "CREATE_IF_NEEDED",
"allowLargeResults": true,
"query": redacted
}
};
var job = {
"configuration": configuration
};
var jobResult = BigQuery.Jobs.insert(job, projectId);
var jobId = jobResult.jobReference.jobId;
Logger.log(jobResult);
}
The first time I ran a very similar query, I got a dialog prompting me for BigQuery permissions, as documented here:
https://developers.google.com/apps-script/guides/services/authorization
I subsequently ran this same script successfully (with slightly different query config). But, then, about 12 hours after first run, I started getting the authorization return quoted above. I thought it might refresh with time, but still get same failure.

Turns out this has been working all along. The authorization error was being generated by my attempt to look at the job results, not by the job itself. Doh!

Related

Unauthorized WebHook callback channel Google push notifications

I am trying to monitor my files in Google Drive.
By getting notifications to the delivery channel.
I've tried everything and tried hundreds of times but every time he tells me:
`
I am using Postman.
Post https://www.googleapis.com/drive/v2/changes/watch
Body:
{"id": "01234567-89ab-cdef-012345***789ab",
"kind":"drive#startPageToken",
"type": "webhook",
"address": "https://nwafith.com/api/notifications"
}
Response
{
"error": {
"errors": [
{
"domain": "global",
"reason": "push.webhookUrlUnauthorized",
"message": "Unauthorized WebHook callback channel: https://www.nwafith.com/api/notifications"
}
],
"code": 401,
"message": "Unauthorized WebHook callback channel: https://www.nwafith.com/api/notifications"
}
}
In the Domain verification
I added:
www.nwafith.com
nwafith.com
Everything looks right but I don’t know exactly where the problem is.
I hope for help
Unauthorized WebHook callback channel:
Means that you have not properly authorized your domain in Google developer console.
Solution:
Go to the Google Developers Console
Select your project
Under 'APIS & AUTH' select 'Push'
Click 'Add domains'
Enter the needed domains (Only the domain is needed: https://www.nwafith.com)
Click the 'Add domains' button
After that it should work.

Where to view watson assistant error logs

A webhook call fails, how do I see the detailed logs?
The testing webhooks page describes that the errors are put in output.webhook_error.<result_variable>. For example if your result variable is webhook_result_1 then the output is in output.webhook_error.webhook_result_1.
As described in the documentation, if an error happens then in the "Assistant responds" section of the dialog node editor, the "If assistant recognizes" anything_else should be used, so you can put in there The callout generated this error: <? output.webhook_error.webhook_result_1 ?>..
This will show more information. For example if I configure an API to throw an Error, I will get back:
The callout generated this error: {"response_code":400,"message":"Webhook call was not successful. Response code is [400].","response_body":{"code":"cff11d18150e8018d5e304ac3fc35c94","error":"There was an error processing your request."},"content_type":"application/json"}.
If this error happens when the Bot is being used live, then in the logs the webhook response body will be captured. If you use the Try It Out panel in the UI then the logs are not captured.
In the Assistant UI for the Skill in the Analytics tab the conversation is shown. In the "User conversations" part of the UI the text of the conversation is captured, but you will only see the webhooks error if you add output as described above.
The API can be used to fetch logs for a workspace or skill which include the webhook error details. See List Log Events in a Workspace. If you are using a Skill then you can find out the URL to use from the Assistant UI. On the Skills list page, on the particular skill click the ... menu and select View API Details. The Legacy v1 workspace URL: shows the workspace ID to use.
For example if the Legacy v1 workspace URL: is https://gateway.watsonplatform.net/assistant/api/v1/workspaces/ce13f844-c3a7-4f36-97c6-a0ac704024a6/message the URL to use to fetch logs is https://gateway.watsonplatform.net/assistant/api/v1/workspaces/ce13f844-c3a7-4f36-97c6-a0ac704024a6/logs?version=2020-04-01
In the workspace log there will be the details of the user conversation where a webhook error happened in webhook_error:
"output": {
"generic": [
{
"response_type": "text",
"text": ""
},
{
"response_type": "text",
"text": "The callout generated this error: {\"response_code\":400,\"message\":\"Webhook call was not successful. Response code is [400].\",\"response_body\":{\"code\":\"cff11d18150e8018d5e304ac3fc35c94\",\"error\":\"There was an error processing your request.\"},\"content_type\":\"application/json\"}."
},
{
"response_type": "text",
"text": "Customer email is <? context.webhook_result_1.message ?>."
}
],
"text": [
"",
"The callout generated this error: {\"response_code\":400,\"message\":\"Webhook call was not successful. Response code is [400].\",\"response_body\":{\"code\":\"cff11d18150e8018d5e304ac3fc35c94\",\"error\":\"There was an error processing your request.\"},\"content_type\":\"application/json\"}.",
"Customer email is <? context.webhook_result_1.message ?>."
],
"nodes_visited": [
"slot_2_1520179906877",
"handler_3_1520179906877",
"node_1_1520179877410",
"node_9_1530805081298",
"response_5_1604940050659",
"node_7_1520180645829"
],
"webhook_error": {
"webhook_result_1": {
"response_code": 400,
"message": "Webhook call was not successful. Response code is [400].",
"response_body": {
"code": "cff11d18150e8018d5e304ac3fc35c94",
"error": "There was an error processing your request."
},
"content_type": "application/json"
}
},
"nodes_visited_details": [

Unable to send message to end user (msteams) via Bot

Facing issue to send proactive message to the end user (msteams), via bot service,
I try using the bot framework python SDK, where I am getting the following error even for getting conversation id.
botbuilder.schema._models_py3.ErrorResponseException: Operation returned an invalid status code 'Unauthorized'
Hence I try to simulate calls via postman and rest API's, in here I am able to get conversation id successfully, but if I try to use that conversation id to further send a message via activities I am not able to do it. following is rest endpoint and payload. In here I am getting an error of incorrect payload.
https://smba.trafficmanager.net/apis/v3/conversations/8:orgid:949a3f72-b82c-4b89-b2de-9defbe6ae7cd/activities
{
"type": "message",
"recipient": {
"id": "29:1ZcsKdk0rsLmsywvI2SNQ2J7OIz"
},
"from": "bot",
"channelData": {
"notification": {
"alert": "true"
}
},
"text": "Hello world"
}
There was an issue with payload, I added BOT_ID along with name and able to successfully post message to end user. Following is working payload.
Payload:
{ "type":"message",
"recipient":{
"id":"29:1dUxQXVlH6QGByu1T9MR4p5g0c5URMaBtKqGU74C3zdowO78nPbuu2dg- qj9o02OkJ4MYXt2I-nxDgf9ga9EY5w"
},
"from":{
"id":"28:d7afe8c9-f0cd-434f-8906-be2b744229ac",
"name":"bot"
},
"channelData":{
"notification":{
"alert":"true"
}
},
"text":"Hello "
}

Why are attempts to view revisions with the Google Drive API returning a 500?

I've been working with the Google Drive API for a bit, accessing the list of revisions for two sheets as part of a job with service.revisions().list(fileId=FILE_ID).execute(). Everything was fine until earlier this morning, when one of the requests (but not the other) started returning a 500 error. This isn't intermittent - it's returning this error on every request so an exponential backoff just hits the cap I've set (5).
There's nothing of value in the response but here it is:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "internalError",
"message": "Internal Error"
}
],
"code": 500,
"message": "Internal Error"
}
}
I get the same error when querying with the API explorer, so this seems to be an issue with the sheet itself as opposed to a coding problem. Here's the request URL:
https://www.googleapis.com/drive/v3/files/1KYDm4gqaCLipQTskbqQbesq8ON7CmV_4IscF8V0FZrs/revisions?key=YOUR_API_KEY
What could suddenly cause this change in behavior?

Google Apps Script and Big Query - tabledate.insertAll

Have been struggling with this..... Google Apps Script and the Big Query API are working well however when I try to use BigQuery.Tabledata.insertAll I keep getting an error saying 'no such field'.
When I try to run the same thing through the Google API explorer it works fine. The documentation says the command is :
BigQuery.TableData.insertAll(TableDataInsertAllRequest resource, String projectId, String datasetId, String tableId)
I have constructed the TableDataInsertAllRequest resource as per the documentation https://developers.google.com/bigquery/docs/reference/v2/tabledata/insertAll and it looks like this :
{
"kind": "bigquery#tableDataInsertAllRequest",
"rows":
[
{
"json":
{
"domain": "test",
"kind": "another test"
}
}
]
}
This matches my table schema.
When I run the command the error returned is :
{
"insertErrors": [
{
"index": 0,
"errors": [
{
"message": "no such field",
"reason": "invalid"
}
]
}
],
"kind": "bigquery#tableDataInsertAllResponse"
}
As I say the same TableDataInsertAllRequest resource works fine in the API explorer (clicking Try It on the documentation page above) it just does not work through Apps Script.
Any help gratefully received.
I've run into this too, and had somewhat better luck with this variation.
var rowObjects = [];
// Generally you'd do this next bit in a loop
var rowData = {};
rowData.domain = 'test';
rowData.kind = 'another test';
rowObjects.push(rowData);
// And at this point you'd have an array rowObjects with a bunch of objects
var response = BigQuery.Tabledata.insertAll({'rows': rowObjects}, projectId, datasetId, tableId);
Some things to note:
I don't indicate a kind -- it is implied by the call to insertAll()
I use dot notation (is that the right term?) rather than strings to stuff attributes into my "row objects"
I'm not sure which of these is the Secret Sauce. Anyways, in the end, the structure of the call looks about like this:
BigQuery.Tabledata.insertAll({'rows' : [
{
'domain' : 'test',
'kind' : 'another test'
}
]
},
projectId,
datasetId,
tableId);