Creating a titled Google Sheets results in a "Proto field" error when using the NodeJs client library - google-sheets-api

I am trying to create a Google Spreadsheet using a NodeJs backend and the Google Sheets v4 API.
I was following the spreadsheets.create tutorial in documentation. However, when I create the file using some specified properties, I always get the following error:
Error: Invalid JSON payload received. Unknown name "title" at 'spreadsheet.properties': Proto field is not repeating, cannot start list.
In the tutorial nothing, is mentioned about a "Proto" field. Is this a bug or am I missing something?
Creating the file does work, if I don't specify properties. However the properties are used to set a name for the file and the sheets, so I do need a way to set this metadata.
Here is the request I am sending with the properties included:
const request = {
auth,
resource: {
properties: {
title: name,
},
sheets: [
{
properties: {
title: 'General',
},
},
],
},
};

Related

Update BigQuery scheduled query with notificationPubsubTopic fails

I am using the DataServiceTransferClient API/SDK for Node to create scheduled queries in BigQuery with a notificationPubsubTopic. Creating them works fine, no issues. Updating them results in an error:
INVALID_ARGUMENT: notificationPubsubTopic cannot be updated.
How I'm calling it:
const config = {
transferConfig: {
/* other config options */
notificationPubsubTopic: "projects/engineering/topics/test"
},
updateMask: {
paths: [
"params.query",
"params.write_disposition",
"params.destination_table_name_template",
"schedule",
"notificationPubsubTopic"
],
},
}
dataTransferClient.updateTransferConfig(config)
Some other info:
The topics I've tested with do exist. I can update the scheduled query in the UI to these other topic with no issue.
Fails even when re-using the already associated topic.
Updates without notificationPubsubTopic succeed. By this I specifically mean I am not passing the notificationPubsubTopic property and have removed it from the updateMask.
The updateMask property needed to be turned into snakecase.
updateMask: {
paths: [
"params.query",
"params.write_disposition",
"params.destination_table_name_template",
"schedule",
"notification_pubsub_topic" // <--- here
],
},
The documentation even shows an example of using camelCasing
https://cloud.google.com/bigquery-transfer/docs/reference/datatransfer/rest/v1/projects.locations.transferConfigs/patch#body.QUERY_PARAMETERS.update_mask

Open API schema conditional response field based on the presence of a query parameter

I am working on providing a GET REST API where I would like to conditionally include the total_documents field (its an integer count of the total number of records present in the DB table).
The API signature and response payload will be something like:
GET /endpoint/?total_documents&.....
Response Payload:
{
documents: [....],
total_documents: 100
}
Now I would like the total_documents field to be appeared in the response payload if and only if the total_documents query parameter exists in the URL.
This is what I tried, based on my schema:
fastify.addSchema({
$id: 'persistence-query-params',
title: "PersistenceQueryParams",
type: 'object',
description: 'Persistence Service GET API URL query specification. Applicable for GET API only.',
properties: {
'total_documents': {
description: 'Total number of documents present in the collection, after applying filters, if any. This query paramater does not take any value, just pass it as the name (e.g. &total_documents).',
nullable: true,
},
},
}
querystring: {
description: 'Persistence Service GET API URL query specification. Applicable for GET API only.',
$ref: 'persistence-query-params#',
},
response: {
200: {
properties: {
'documents': {
description: 'All the retrieved document(s) from the specified collection for the specified service database and account.',
type: 'array',
items: {
$ref: 'persistence-response-doc#',
}
},
'total_documents': {
description: "If total_documents query paremeter is specified, gives the total number of documents present in the collection, after applying query paramaters, if any. If total_documents is not specified, this field will not be available in the response payload.",
type: 'number',
default: -1,
},
},
dependencies: {
'total_documents': { required: ['querystring/properties/total_documents'] },
},
},
'4xx': {
$ref: 'error-response#',
description: 'Error response.'
}
}
What is the way out here?
Thanks,
Pradip
JSON Schema has no notion of a request or response or HTTP.
What you have here is an OpenAPI specification document.
The OpenAPI specification defines a way to access dynamic values, but only within Link Objects or Callback Objects, which includes the query params.
Runtime expressions allow defining values based on information that
will only be available within the HTTP message in an actual API call.
This mechanism is used by Link Objects and Callback Objects.
https://spec.openapis.org/oas/v3.1.0#runtime-expressions
JSON Schem has no way to reference instance data, let alone data relating to contexts it is unaware of.

How to use Atlassian Document Format in create issue rest api

I am trying to create an issue via Jira API -
{
// other fields is here
description: {
type: "doc",
version: 1,
content: [
{
type: "text",
text: summary
}
}
}
but I get an error - "Operation value must be a string".
so how can I create an issue correctly?
Most likely you're using API version 2 - which accepts text for this field.
However, you're providing value as json (Atlassian Document Format) which is for API version3

Is there a way in the Google Sheets API to access the script editor?

For example, I'd like to write a (Python, say) program that generates a Google sheet, then writes some custom .gs code into the Apps Script attached to that sheet, then writes values into the sheet itself using formulas defined in the Apps Script. What I currently do is use Tools > Script Editor, then manually copy-paste the relevant Apps Script code.
As mentioned by #Tanaike, You can use Apps Script API to add container-bound script.
(OPTION 1: Writing the function manually in the script content)
What to do:
Create a container-bound script using projecs.create method.
To set a container-bound script, you need to assign the spreadsheet file id to the parentId parameter
Sample Request Body:
{
"title": "new",
"parentId": "spreadsheet file id"
}
Get the newly created container-bound script id in the project response body of projecs.create method.
Sample Response Body:
{
"scriptId": "newly created script id",
"title": "new",
"parentId": "spreadsheet file id",
"createTime": "2020-12-25T23:33:48.026Z",
"updateTime": "2020-12-25T23:33:48.026Z"
}
Update the content of the newly created bound script using projects.updateContent method and include your function.
Sample Request Body:
{
files: [{
name: 'hello',
type: 'SERVER_JS',
source: 'function helloWorld() {\n console.log("Hello, world!");\n}'
}, {
name: 'appsscript',
type: 'JSON',
source: "{\"timeZone\":\"America/New_York\",\"" +
"exceptionLogging\":\"CLOUD\"}"
}]
}
(OPTION 2: Copy an existing script and paste it as bound script)
Create a standalone script that will contain your custom functions.
Get the newly created standalone script project content using projects.getContent which will return a content resource
scriptId can be seen in your standalone script project under File -> Project Properties
Create a container-bound script using projecs.create method.
To set a container-bound script, you need to assign the spreadsheet file id to the parentId parameter
Sample Request Body:
{
"title": "new",
"parentId": "spreadsheet file id"
}
Get the newly created container-bound script id in the project response body of projecs.create method.
Sample Response Body:
{
"scriptId": "newly created script id",
"title": "new",
"parentId": "spreadsheet file id",
"createTime": "2020-12-25T23:33:48.026Z",
"updateTime": "2020-12-25T23:33:48.026Z"
}
Update the content of the newly created bound script using projects.updateContent method.
Use the content resource returned in Step 2 as the request body. Make sure to replace the script id based on the newly created bound script id that is obtained in Step 4.
Example Standalone Script:
Example Result of the Workaround:
You can now use the custom function in the Google Sheets

How to configure dynamic links for a Firebase project?

Since google is shutting down it's url shortening service, I want to move my project to FDL.
I am using the api to shorten the url following this:
https://firebase.google.com/docs/dynamic-links/rest#create_a_short_link_from_a_long_link
and I am using Postman to call the api but I keep getting this error.
{
"error": {
"code": 400,
"message": "Your project has not configured Dynamic Links. [https://firebase.google.com/docs/dynamic-links/rest#before_you_begin]",
"status": "INVALID_ARGUMENT"
}
}
I am using the correct api key and the project id.
Had the same issue- and thats the answer i got from the firebase team:
Take note that to be able to view your Dynamic Link domain you'll have
to add an app first. If you're using Firebase Dynamic Link as a
substitute to Google Shortener, you can create a sample application
(dummy app) for your project to proceed creating a Firebase Dynamic
Links. Just enter dummy values for the iOS bundle ID or Android
package name (ex: “my.dummy.app”) to continue.
then you'll put the id you'll get from it (e.g. https://dedfgu.app.goo.gl) instead of the place holder (https://abc123.app.goo.gl).
Good luck!
You can try following way
var Url = "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key={API-Key}";
$.ajax({
type: 'POST',
dataType: 'json',
url: Url,
contentType:'application/json',
data: JSON.stringify({
"dynamicLinkInfo": {
"domainUriPrefix": "https://newxpress.page.link",
"link": {Your-Link},
"androidInfo": {
"androidPackageName": "com.newxpress"
},
"iosInfo": {
"iosBundleId": "com.newxpress.iosapp"
}
}
}),
success: function (jsondata) {
console.log(jsondata);
},
error: function (result) {
console.log(result);
}
});