Forum Academy Marketplace Showcase Pricing Features

Context.request timeout

Does anyone know if context.request has a timeout in anyway? I’m using it in a server side action (post request) to send JSON data (in body) back into my database using the workflow API URL. Although it actually works and I can see the data in my table, the client always throws an error to say…

Just wondered if anyone else experienced it or better still if there’s a way to set my own timeout value!

function(properties, context) {
    
    var api_token = properties.api_token;
    var transcript_id = properties.transcript_id;
    var bubble_api = properties.bubble_api;
    
    if (api_token && transcript_id && bubble_api) {
        
     // make get request to assembly ai and retrieve transcription id
        let get = {
            uri: "https://api.assemblyai.com/v2/transcript/" + transcript_id + "",
            method: 'GET',
            headers:{
                authorization: api_token,
                "content-type": "application/json",
            },
            json: true
        };
        
        let result = context.request(get);
        let json = result.body;
        
        
     // make post request to bubble and send the data we got above
        let post = {
            uri: "" + bubble_api + "",
            method: 'POST',
            headers:{
                "content-type": "application/json",
            },
            body: json,
            json: true
        };
        
        context.request(post);
        
        
     // return the transcription json back to bubble
        return {
            json: JSON.stringify(result.body)
        };
        
    }

}

You’ll probably want to warp your api calls into an async/await code block. You’re making api calls without waiting for the response. The code doesn’t infer that it must wait for context.request() I don’t believe.

Unfortunately I tried that also and I get the same message :frowning:
I’ll have a play and make sure it’s actually doing it corretly.

It’s been changed to this but it still mis-behaves. I’m not too sure if I can do anything about it

Update (for mine and anyone else searching for similar)
This now works, thank you :slight_smile:

function(properties, context) {

    var api_token = properties.api_token;
    var transcript_id = properties.transcript_id;
    var bubble_api = properties.bubble_api;
    var json;
    var result;

    if (api_token && transcript_id && bubble_api) {

     // make get request to assembly ai and retrieve transcription id
        const promise1 = new Promise((resolve, reject) => {

            let get = {
                uri: "https://api.assemblyai.com/v2/transcript/" + transcript_id + "",
                method: 'GET',
                headers:{
                    authorization: api_token,
                    "content-type": "application/json",
                },
                json: true
            };

            result = context.request(get);
            json = result.body;

        });

        promise1.catch((error) => {
            console.error(error);
        });


     // make post request to bubble and send the data we got above
        const promise2 = new Promise((resolve, reject) => {

            let post = {
                uri: "" + bubble_api + "",
                method: 'POST',
                headers:{
                    "content-type": "application/json",
                },
                body: json,
                json: true
            };

            context.request(post);

        });

        promise2.catch((error) => {
            console.error(error);
        });

     // return the transcription json back to bubble
        return {
            json: JSON.stringify(json)
        };

    }

}
2 Likes

Nice workkkk! :mechanical_arm: Gotta wait on those dang promises!

Haha yeh, thanks for the pointer in the right direction!

Geeeez what’s this all about now!!

image

This only happens when I fudge my server side code. There’s a really unhelpful js verifier process at play that finds errors on SSA bu can’t really help you understand what’s going on or where the error occurs from top down.

I’ll throw in a slot on the idea board to improve the ide features for the plugin editor. Right now it’s basically a sometimes sluggish text editor that spits out plugins.

I’m often switching between jsfiddle and the plugin editor to check for errors and keep things tidy

Is this your only action ^^^^^^

Ok thanks.
Yep just one action in this one to help a friend out. I’ll run it through a JS parser and make sure all is good.