URL/Callback URL action step and subsequent steps

Simple version of my question

Say that I have an action with a URL step like https://www.guardian.co.uk, or a callback URL step like firefox://open-url?url=https://www.guardian.co.uk. How do I make sure that action steps subsequent to the URL/callback URL steps run?

At the moment these steps cause my action to pause indefinitely, causing the iOS Drafts app to hang. I’m new to callback URL schemes, and any solution that allows me to open a URL without a URL/callback URL step (such as in a script step) would also be very welcome.

The gory details

The longer version of this question is that I’ve finally figured out how to run a Google Apps script from Drafts. I have a Google Apps script that writes student names and grades to a spreadsheet, and I’ve deployed it as a web app. I have a “Grade Participation” action that prompts me for the class date, and then runs through the array of students and asks me to input grades for each of them. Finally it encodes this data as the parameters appended to the web app URL, building the full URL using template tags as follows:

https://script.google.com/macros/s/[[webappid]]/exec?[[params]]

But the subsequent steps, which involve writing the data to a draft as a backup record of my students’ grades, don’t run after the URL step (on my Mac) or the callback URL step (on iOS).

My understanding is that a solution via a callback URL should involve something like firefox://open-url?url=[[url]]&x-success=drafts5://, but I have not been able to get this to work.

Your URL is a web page in a browser, not an app. As such it would not be capable of supporting x-callback-url, which is what is required for this approach to return data you can utilise in Draffs.

Take a look instead at setting up your script as an API and the Drafts HTTP functionality in scripting for interacting with an API. This then cuts out the browser and in effect then allows Drafts to talk directly to the Google Apps platform.

Hope that helps.

1 Like

Do you have a pointer for the APIs you are using at Google? We might be able to help you construct the appropriate script to call that API. Most APIs require you make HTTP POST requests, which is not something you can do with URL/Callback steps – they are the equivalent of HTTP GET requests that open web pages.

1 Like

Thank you very much, @sylumer, that sounds like a much more robust solution than using a URL. As it happens, I figured out that just opening the URL within a script step does the trick, as follows,

const url = `https://script.google.com/macros/s/${course.webappid}/exec?${paramStr}`;
app.openURL(url);

But I’m going to try your version. Captain @agiletortoise, hopefully I’ll have a better sense of what you mean once I’ve implemented @sylumer’s solution. :upside_down_face:

1 Like

Are you saying that switching to opening the URL using a script step is somehow returning the data to the draft for you?

I’m afraid that doesn’t make any sense to me given the code you posted. It just looks like the equivalent of the URL action, so nothing to receive the output from script and place it in the draft.

No, I don’t need the URL to return any data. What the URL does is to pass paramStr to a doGet(e) function in my Google Apps script, which parses the parameters and passes them to another function, which writes them to a Google spreadsheet. You were probably misled by my writing

the subsequent steps, which involve writing the data to a draft as a backup record of my students’ grades

What I meant was that the subsequent steps write the data taken in by the prompts within Drafts to a draft as a backup in case the data doesn’t get properly written to my spreadsheet.

Yes, that was misleading me. My understanding from what you wrote was data was coming back from the script to Drafts to be recorded.

To use items of data in the URL action you would use Drafts’ template tags (there are Drafts and Mustache flavours). However, if they do not conform to specific Drafts elements (e.g. the title, or a specific line), chances are you would need code to specify custom tagd and so there would be little benefit at that point in splitting it out into a URL step to trigger the URL.

1 Like