How to use a catalog of items objects to send to Rest API

Hello.

I try to reach a Rest API to send thousands of items, one by one, using by a POST request.
So I have a collection of items. Each time my test is executed, one of those items is sent. Each item is sent an only time. If the Rest API receives an item two times, it should throw an exception. I don’t want that.
I did not found examples for this case on your documentation.
Could you help me please ?

Today, I can send an only item :

export default () => {
  group('LeRefuge incoming message smoke test', () => {
    group('Send SMS using by WhatsApp', () => {
      const url: string = `${ngrokUrl}/api/1/Message/Incoming`;
      const body: StructuredRequestBody = { smsSid: '', From: '', };
      const params: RefinedParams<'text'> = {
        headers: {
          Authorization: leRefugeToken,
          'Content-Type': 'application/x-www-form-urlencoded',
          'X-Twilio-Signature': '',
        },
      };

      const res: RefinedResponse<'text'> = http.post<'text'>(url, body, params);

      console.error(res.status);
      console.error(res.body);
      console.error(res.error);

      check(res, {
        'status is 200': () => res.status === 200,
      });
      sleep(1);
    });
  });
};

Thanks.

Hi @MaximeAUBRY.Modis, welcome to the community forum!

I don’t exactly understand your question especially with the example you are given.

So I have a collection of items.

I see no such thing in the example code.

Each time my test is executed, one of those items is sent

are we talking here each time you call k6 run script.js or on each iteration. I guess it’s the second, but the way it’s worded seems like the first.

I guess you need the info in Retrieving unique data. AM I correct?

If not can you expand a little bit and explain what you mean by “I have a collection of items.”

Thanks a lot.

Data Parameterization (k6.io) was the solution.

If you want withing one execution of k6 run script.js where there will be multiple iteration executed to not have repeated execution you can use Retrieving unique data as I meantioned above.

If you have to do between execution os k6 run you will need to know how many items you need to skip - you have done 1021 iteration with previous executions (for example) so you will need to give this to k6 somehow and start from that instead from the begining. This can be done through environmental variables for example. And you can then for example just add that to scenario.iterationInTest from the link above.

thanks