Hi there, wondering if anyone might have an idea of where I could start looking to resolve this error I’m having. I’m trying to setup a receipt exporting process and it’s all mostly working but I thought I would look into Scriptable as a means of setting a timeout period instead of hoping the Shortcuts version will last long enough. The POST request that I’m sending off is a rather large one so I’ve got a relatively high timout period but I’m not getting the result I was expecting.
Without running the script in App from Shortcuts, it will process thinking about it for ~8 seconds before the shortcut just dies without an error message or anything. If I force the Scriptable to run in app, as soon as the app opens it shows a notification that says “ERROR Something went wrong, unable to upload file”. Because of some problems I had working with the PDF I’m sending being processed in my handler, I’m not actually sending the file as a blob but rather a base64 encoded string that is sent along with a JSON payload, so I’m not sure what file it’s talking about.
The stragest thing is that looking at the endpoint and it’s process though, it does get called and runs to completion successfully despite the error showing. However, I think due to the error, the Scriptable stops running and despite the await request.loadJSON(); it does not wait for the response to handle the return.
If anyone has any suggestions of where I could look for trying to find where this process is going wrong I would be very appreciative
For reference, this is the Scriptable script that I am trying to run:
// Get the values that are needed for the request being sent
let jsonPayload = args.shortcutParameter.jsonPayload; // The payload that is going to be sent with the request
let endpoint = args.shortcutParameter.endpoint; // The endpoint that is to be reached by the request
let method = args.shortcutParameter.method; // The request method that will be used when sending. E.g. GET, PUT, POST, etc.
let timeout = args.shortcutParameter.timeout || 60; // How long (in seconds) should the request be allowed to run for
// Create the request with the given values
let request = new Request(endpoint);
request.method = method;
request.headers = { "Content-Type": "application/json" };
request.body = JSON.stringify(jsonPayload);
request.timeoutInterval = timeout;
// We're going to send the request and handle the return values
try {
let response = await request.loadJSON();
Script.setShortcutOutput(response);
}
// Anything goes wrong, that's a problem
catch (ex) {
console.error(`Failed to process the request to '${endpoint}'. ERROR: ${ex}`);
Script.setShortcutOutput({ error: ex.message});
}
// Mark the script as complete to speed up the handling of the shortcut output
Script.complete();
And this is the input into the Scriptable action that I have in the Shortcut. I’m supplying all the information via a Dictionary and it does appear to read all the information as expected.
Upon further investigation, it’s looking like that problem might be from the size of the request that is being sent. If I don’t include the encoded file in the request that is being sent it looks like everything works as expected
I have tried adding the raw file data to the request instead of it being encoded but kept running into exceptions that were raised from the data not being formatted properly. If that seems like a good way to go, would anyone have any guidance on how to format the data in a way that can be sent properly?
I found in the Sciptables Docs that the Request object has some specific functions for adding file data to the request as a part of a multipart form request. I’ve tried using addFileDataToMultipart to add the data and it doesn’t seem to be coming through. When using the addParameterToMultipart function to add my JSON data, that comes through but nothing for the file data. If I remove the JSON entry and just use the file, still nothing comes through.
Ok, progress! I ended up having to go back to encoding the file as a string and having it send that way, but I did find that it is running. When I enable the “Run in App” option for Scriptable it shows an error but that is just the shortcut failing on the Scriptable action. The Scriptable actually continues running for the duration of the request as I would expect. I suspect that when I run the Scriptable as a part of my Shortcut, those 8 seconds are how long the action is given to run before it just fails silently.
Does anyone have a way or know how to prevent that from happening? The main reason I went to use Scriptables was for being able to set the request timeout so it could go reliably for longer then a minute but if it’s going to die after 8 seconds, I may have to rethink my approach
Ah yes. I did some checking and looks like the running limit is something a few other people have run into as well. Looks like I might have to go down the x-callback-url route for raising the functionality. Thank you for that link, I’ll give it a crack and see what I can get working