Is there a way in the Google Sheets API to access the script editor? - google-sheets-api

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

Related

Outlook 365 file attachment option auto-applies CSV column headers

I need to develop an integration using Mule which will create a *.csv file without headers, and email the file content as email attachment using Outlook 365.
Using DataWeave 2.0, I defined output application/csv header = false to create required CSV content without headers. Output of the DataWeave script is correct, which I checked in application logs and also by writing to local file system.
In the next step, I am passing this output payload to Outlook 365 using below code (MuleSoft Outlook 365 connector internally uses Outlook mail REST API - https://learn.microsoft.com/en-us/graph/api/resources/mail-api-overview?view=graph-rest-1.0):
%dw 2.0
import * from dw::core::Binaries
output application/json
---
{
"message": {
"subject": "Summary-" ++ now() as String {
"format": "yyyyMMdd"
},
"body": {
"contentType": "Text",
"content": "Please find attached summary"
},
"toRecipients": [{
"emailAddress": {
"address": p('outlook.toRecipients')
}
}],
"attachments": [{
"#odata.type": "#microsoft.graph.fileAttachment",
"name": "service-data.csv",
"contentType": "application/csv",
"contentBytes": toBase64(write(payload, "application/csv"))
}]
},
"saveToSentItems": "true"
}
Receiver of this email finds column headers created in the attached file, example:
column_0,column_1,column_2,column_3,column_4,column_5,column_6,column_7,column_8,column_9,column_10,column_11,column_12,column_13,column_14,column_15,column_16,column_17,column_18
,SDEN1001107GR,Dense 7.3N 100mm,Days,0,,Blank,,,,,,,,,,,,
I debugged this, and looks like Outlook 365 connector automatically adds column header 'column_X' if not defined. But, the requirement is not to include headers in the file attachment.
Could anybody please help how to ignore the column headers in email attachment?
Sample request payload:
[
{
"Code": "SDEN1001107GR",
"UnitUsagesUsage": "Days",
"Group": "Blank",
"Category": "A",
"Description": "Dense 100mm",
"Rate": "0"
}
]
The issue seems to be that DataWeave -not the connector- is receiving the header=false property as a reader property rather than a writer property. For example in the read() function or in the outputMimeType attribute of a source or operation. Reader properties apply to the input of the script.
You need to use as a writer property instead for the property to be applied to the output.
In the write() function you add writer properties as an additional parameter:
write(payload, "application/csv", {header: false})

How to POST json parameters from Postman to Jenkins?

I need to call a Jenkins job using its API through Postman. This job requires parameters (HOST, VERBOSITY and PMSP).
Auth works using Jenkins token and header Content-type:application/json is used.
I tried to call the endpoint https://jenkins_server/job/job_name/build/api/json adding the following body to the request but the result is Nothing is submitted, and the job doesn't run.
I tried to call the endpoint https://jenkins_server/job/job_name/buildWithParameters/api/json adding the same body. I get 201 Created (job is running) but no parameters are given to the job.
{
"parameter": [
{
"name": "HOSTS",
"value": "[linux]\n1.2.3.4"
},
{
"name": "VERBOSITY",
"value": "vv"
},
{
"name": "SANS_PMSP",
"value": true
}
]
}
Is my JSON well constructed ? Which endpoint do I need to call ?
If it's Postman that you would like to focus on, you can import the curl command straight into the application.
This creates a new request for you to use and it populates this request, based on the details in the command.
From here, you should be able to add your own URL and point this at the location you need.

Usage for displayNewMessageForm with unsaved attachments possible?

We are working on an Office AddIn for Outlook and we need to open a new message with predefined data we are getting from our own rest-interface in Json format like this:
{
"attachmentNo": "1",
"Content-Type": "application/pdf;",
"name": "CPV - Lohnbeilage Planwahl_2018_Lohnbeilage_D.PDF",
"Content-Transfer-Encoding": "base64",
"Content-Disposition": "attachment;",
"filename": "CPV - Lohnbeilage Planwahl_2018_Lohnbeilage_D.PDF",
"content": "JVBERi0xLjUNCiW1tbW1DQoxID....",
"fileType": "pdf",
"fileSize":"15MB"
}
To provide an attachment for the displayNewMessageForm Method I need the format:
{
type: 'file',
name: "CPV - Lohnbeilage Planwahl_2018_Lohnbeilage_D.PDF",
url: ???,
isInline: false
}
Is there any possibility to use something like a data-url like this:
'data:application/octet-stream;charset=utf-8;base64,JVBERi0xLjUNCiW1tbW1DQoxID....'
as url or is there another trick how I can manage to add an unsaved attachment to the new message?
Currently there is no way to pass base64 attachments as part of the displayNewMessageForm API. We track Outlook add-in feature requests on our user-voice page. Please add your request there. Feature requests on user-voice are considered when we go through our planning process.
Meanwhile we do have an API that lets you add base64 attachments to the current Item (documentation). What you can do is the following: once the new form opens, open the add-in, call into this API to add the attachment. Note that this API is in preview (prone to changes) and currently only available in Outlook Desktop for build numbers > 16.0.10730.1000.

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

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',
},
},
],
},
};

POSTMAN COLLECTION RUNNER: passing the all body post request as a variable?

I have a POST request template - instead putting all the JSON body i put a variable: {{bodyRequest}}
now i have a json file that looks like this(Below code bloc) that i upload in my collection runner as data json: my intention is to fetch {{bodyResponse}} from the iteration and make the post call in the api.
[
{ "{{bodyRequest}}":
{
"order": {
"order_date":"{{$timestamp}}",
"order_number":"{{$guid}}",
"reference":"Scenario1",
"destination":
{
"name":"test",
"phone":"00000",
"email":"test#test.com",
"company":"My Company",
"building":"My Building",
"street":"my street",
"suburb":"my sububr",
"post_code":"my postcode",
},
}
}
}
]
Then i click run
Open Collection Runner
Add Data file in Format JSON (above in code)
declare it as Json
run collection
Error Log
Request Body:"{{bodyRequest}} "
instead the all payload
thank you so much
Franco