0

I am working on some task automation from a Google Spreadsheet. I need to use Adobe Sign API to complete the process. I just started using AppScript last week, so I'm not sure if what I'm doing is right...

From the spreadsheet, I trigger a function that will open the oAuth request link of Adobe Sign to a new tab. User will sign in and click Allow Access. The redirect_uri I have setup is to the same spreadsheet so if the request is successful, it will redirect to the spreadsheet and the authorization code is included in the URL by Adobe Sign. (e.g. https://docs.google.com/spreadsheets/d/[spreadsheetId]/edit?code=[authorizationCode])

How do I get value for code parameter in the URL?

Adobe API reference for making an oAuth request - https://opensource.adobe.com/acrobat-sign/developer_guide/gstarted.html#create-an-authorization-request-link

I tried using e.parameter on onOpen event like below but its resulting into an error

TypeError: Cannot read properties of undefined (reading 'code') at onOpen

    function onOpen(e) {
      const code = e.parameter["code"];
      console.log(code);
    }

I have also tried implementing doGet(e), but not sure if I was doing it correctly. I'm getting error

TypeError: Cannot read properties of undefined (reading 'parameter')

I added a menu to trigger the doGet function:

function onOpen(e) {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Document control')
 .addItem('Do Get', 'doGet')
 .addToUi();
  const code = e.parameter["code"];
  console.log(code);
}

function doGet(e){
  var code = e.parameter.code
  console.log(code);
}
10
  • If the spreadsheet is open then the SpreadsheetApp.getActive().getUrl() should work Commented Feb 11 at 7:00
  • @Cooper The OP isn't interested in the URL as such; they want to return a parameter value for "Code" (which is part of the URL). I think this involves a doPost(e) (or maybe doGet(e)) - you will know much more about this than me. Possibly related question?? doPost(e) does not return parameters but doGet(e) does? Commented Feb 11 at 10:36
  • @Tedinoz You may be correct I can't tell from the OP's question myself so I'll just wait for further clarification from them Commented Feb 11 at 16:03
  • Related question: How to get a URL string parameter passed to Google Apps Script doGet(e). Event objects for onOpen are limited and don't apply to" e.parameter. You need a different approach. Commented Feb 12 at 2:24
  • @Cooper I did try using the getUrl() but it doesn't include the parameters in the returned value. It only returned something like this: docs.google.com/spreadsheets/d/[spreadsheetId]/edit I needed to get the value of the code parameter Commented Feb 12 at 8:15

1 Answer 1

0

Tl; Dr: Regarding your use case, you might take advantage of the OAuth library for Google Apps Script published by Google on GitHub -> https://github.com/googleworkspace/apps-script-oauth2


Google Apps Script has no method to get the URL from the web browser address bar used to open a spreadsheet.

One option is to run a JavaScript statement using the developer tools of your web browser. Another option is to use a bookmarklet, a userscript among other possibilities.

Example

Assuming that you are familiar with Google Chrome dev tools and already know how to run a JavaScript statement, you could use the following:

window.location.href
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.