0

I have a scenario where I am allowed to pass maximum of 100 lat and long separated by semicolon(;) as query parameter in one API request. I got total of 100,000 lat long to pass which I need to iterate and send get request. I have tried the pre-request script but not having enough luck to achieve my actual request.

My array variable sample:

const numbers= ['-39.32939098,173.80391646;',
    '-35.13188244,173.43837148;',
    '-35.96790802,174.22052708;',
    '-39.60085901,174.27450675;',
    '-46.89935626,168.12957415;',
    '-40.94922683,175.66038897;',
    '-40.57392064,175.39045103;',
    '-37.67488205,175.06674793;',
    '-37.77800560,175.22295017;'
]

I have written the following function to pass every 2 lat long in an array.

function fetchEveryNthArguments(){
    const output =[];
    let j=2;
    for (let i = 0; i<numbers.length; i++) {

        output.push(numbers.slice(i, j));
        i++;
        j= j+2;

    }

    return output;
}

API will only accept lat long as query parameter without single quotes or double quotes.

Accepted API Endpoint:

https://api.weather.com/v3/aggcommon/v3-wx-observations-current?geocodes=-37.683334,176.166672;-36.848461,174.763336&language=en-US&units=m&format=json&apiKey=yourAPIkey

On my pre-request script If I call my fetchEveryNthArguments functions. It ends up in error.

Is there any way I can achieve this ?

Ragavan Rajan
  • 4,171
  • 1
  • 25
  • 43

0 Answers0