I need to implement this request in Karate:
curl --location --request POST 'https:/myURL/' \
--header 'Authorization: Bearer myToken' \
--form 'csv=@"newUser.csv"'
PS: newUser.csv file is in the same folder as my feature
This is how I am sending my request on Postman:
I tried this:
Scenario: Bulk New Users - csv file with 1 user
Given header Authorization = accessToken
And multipart field csv = { read: 'newUser.csv', contentType: 'multipart/form-data' }
When method post
Then status 202
But getting 400
I also tried this:
Scenario: Bulk New Users - csv file with 1 user
Given header Authorization = accessToken
And form field csv = { read: 'newUser.csv' }
When method post
Then status 202
And it's like I'm not sending anything
Finally, if I try this:
Scenario: Bulk New Users - csv file with 1 user
Given header Authorization = accessToken
And multipart file csv = { read: 'classpath:newUser.csv'}
When method post
Then status 202
Getting: "could not find or read file: classpath:newUser.csv"
Don't know what I am doing wrong here, I see a lot of examples on internet, none of them worked for me, appreciatte your help on this. thanks in advance
EDIT:
I tried the solution given by Peter but now, I am getting a message from my service that only CSV files are allowed:
Which will be the case when I not attached the csv file or use a file with different extension:
And this is how it looks the request on Karate logs:
It seems I am not sending anything as a body after the conversion to string
Make this change:
* def fileContents = karate.readAsString('classpath:newUser.csv')
* multipart file csv = { value: '#(fileContents)' }