K6: 401 Unauthorized Response on Post Request using Bearer Token Authorization type

Created on 15 May 2020  路  2Comments  路  Source: loadimpact/k6

Environment

  • k6 version: k6/0.26.2 (https://k6.io/)
  • OS and version: Windows 10

Expected Behavior

Post request should create a data with provided extracted Bearer token and payload data

Actual Behavior

401 Unauthorized Response

Steps to Reproduce the Problem

  1. `k6Perf.js:

K6_1

  1. In first function I am extracting the Bearer token and storing it in var token and passing the var onto second function that will create a data.

  2. K6 response Log:
    K6_2

K6_3

Please let me know what am I doing wrong. I was able to send the same post request using JMeter, Postman and Rest Assured....I been trying to get this done and add this script as my Load Test Stage into my GitLab CI Pipelines. But I am struck :(

Thank you in advance!

question

Most helpful comment

The parameters used in the post method are in the wrong order, the correct order would be:

image

  let res = http.post(`${API_SERVER}/api/donors`, {
    ...body
  }, {
    headers
  });

All 2 comments

The parameters used in the post method are in the wrong order, the correct order would be:

image

  let res = http.post(`${API_SERVER}/api/donors`, {
    ...body
  }, {
    headers
  });

It is working now :) Thank you so much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

athoune picture athoune  路  3Comments

StephenRadachy picture StephenRadachy  路  3Comments

caalle picture caalle  路  4Comments

ampc picture ampc  路  4Comments

jrm2k6 picture jrm2k6  路  4Comments