1

I am trying to set up a onEdit trigger for Google SHeets using the Apps Script API. I have managed to create and update a script project by the code given below (this is working fine)

const createScriptRes = await this.script.projects.create({
  requestBody: {
    title,
  },
})
if (createScriptRes.err) {
  responseObj.err = createScriptRes.err
  return responseObj
}
const scriptId = createScriptRes.data.scriptId

const updateScriptRes = await this.script.projects.updateContent({
  scriptId,
  auth: this.auth,
  resource: {
    files: [
      {
        name: 'gsheet_trigger',
        type: 'SERVER_JS',
        source: `
            function onEdit(e) {
              UrlFetchApp.fetch("http://localhost:3000/webhooks/gsheet", {
                'method' : 'post',
                'contentType': 'application/json',
                'payload' : JSON.stringify({ rowInd: e.range.getRowIndex() })
              })
            }
            function setup() {
              const sheet = SpreadsheetApp.openById("SHEET_ID")
              ScriptApp.newTrigger("onEdit").forSpreadsheet(sheet).onEdit().create()
            }
          `,
      },
      {
        name: 'appsscript',
        type: 'JSON',
        source: `{"timeZone":"America/New_York","exceptionLogging": "CLOUD", "executionApi": {
          "access": "ANYONE"
        }}`,
      },
    ],
  },
})

Now, I am facing "Requested entity not found" when I try to deploy this script project using the below code.

const deployScriptRes = await this.script.projects.deployments.create({
  scriptId,
  requestBody: {
    versionNumber: 1,
    manifestFileName: 'appsscript',
  },
})

The full error body is

errors: [
    {
      message: 'Requested entity was not found.',
      domain: 'global',
      reason: 'notFound'
    }
  ]

I have looked for the solution on documentation, github issues and StackOverflow, but didn't find anything specific to this

1 Answers1

0

Try changing requestBody to resource and remove extra comma:

const deployScriptRes = await this.script.projects.deployments.create({
  scriptId,
  resource: {
    versionNumber: 1,
    manifestFileName: 'appsscript' //remove comma at end
    },
  })
Clark Lind
  • 86
  • 4