Test Script Error with sendRequest

I want to run the API until the expected result is achieved with some delay
but getting this error

var expectedStatus = "FINISHED";
var maxIterations = 10;



function runRequest(iteration) {
        var url = pm.environment.get("betaUrl");
        var token = pm.environment.get("token");
        console.log(token);
        var Url = "{{$url}}?authorization={{$token}}";
        console.log(`url: ${Url}`)
    pm.sendRequest(' https://mintapi.beta.thesilverlabs.com/graphql?authorization=23ec24bf1a722c0e92c049146fef63bd14ce1cccb25e37e9e8210a804a495c2b', function (err, response) {
        console.log(`response: ${JSON.stringify(response)}`)
        console.log(err)
        var responseBody = response.json();
        var currentStatus = responseBody.data.dominoTemplateVideoById.status;


        if (currentStatus === expectedStatus) {
            pm.visualizer.set(`
                <p>Iteration: ${iteration}</p>
                <p>Status: ${currentStatus}</p>
            `);
            return;
        }

        if (iteration === maxIterations) {
            pm.visualizer.set(`
                <p>Reached maximum iterations of ${maxIterations}</p>
                <p>Last checked status: ${currentStatus}</p>
            `);
            return;
        }

        pm.visualizer.set(`
            <p>Iteration: ${iteration}</p>
            <p>Status: ${currentStatus}</p>
            <p>Waiting for ${expectedStatus}...</p>
        `);

        setTimeout(function () {
            runRequest(iteration + 1);
        }, 2000);
    });
}

runRequest(1);

The error is telling you what is wrong.

I canโ€™t vouch for the rest of the code, but the current problem is with the targeting of the status in this line.

var currentStatus = responseBody.data.dominoTemplateVideoById.status;

Can you post the response that is returned?

Console log the responseBody from the previous line. Expand the console log out so it shows all of the elements before creating the screenshot please and someone here should be able to help you with targeting the status correctly.

It would appear that your send request is failing.

Therefore its not responding with the body that you are expecting.

You will need to read the API specification to find out how to format the request correctly.

The error states โ€œMust provide query stringโ€ as a starter for 10.

Get the sendRequest() working outside of the function first.