Hello k6 community!
Trying to figure out how to send POST request with JSON payload using k6. Example of a working curl request:
curl --location --request POST 'http://localhost/api/v4/projects/51/repository/commits' \
--header 'PRIVATE-TOKEN: ********' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{
"branch": "branch_name",
"commit_message": "commit message",
"start_branch": "test",
"actions": [
{
"action": "create",
"file_path": "test.md",
"content": "#some content"
}
]
}'
Code I was trying to use:
let params = { headers: { "Accept": "application/json", "PRIVATE-TOKEN": `${__ENV.ACCESS_TOKEN}` } };
let body = {
branch: 'test',
commit_message: "test-commit",
actions: [
{
action: "create",
file_path: "test.md",
content: "#Test commit"
}
]
};
http.post(`${__ENV.ENVIRONMENT_URL}/api/v4/projects/${data.projectId}/repository/commits`, body, params);
Iām getting 400 response error - actions
array is being interpreted as invalid. Could you please clarify if there is a way to send such request using k6?
Worth noting that also tried to send the payload as a JSON file, still not successful.
Links:
- API docs: Commits API | GitLab