Reputation: 253
So I created a dynamic POST Request using the features in Karate. I tested out the newly created request manually and It did return a 200. However, when running the request through Karate, I am getting a 415 Unsupported media type.
POST REQUEST:
{
"content": [
{
"assetId": "273108817",
"country" : "US",
"sourceSystemCode" : "GE_Clarify",
"serviceRequestCode" : "Karate-Insert: 157264280",
"serviceRequestTypeCode" : "servicerequestcorrective",
"serviceRequestStatusCode" : "Started",
"requester" : "Karate,DSL",
"problem" : "Submitted Using Karate",
"submissionTimestamp" : null,
"sourceUpdateDate": "2017-09-13T15:53:51.597Z",
"completionDate" : null,
"dueDate" : null,
"availabilityDate" : null,
"remotely" : "0",
"assetAvailability" : "Up",
"facilityCode" : "US_294629"
}
]
}
Karate Syntax
Scenario: Submit a new Service Request POST:
def ServiceRequestPostTemplate = read('classpath:testsuite/testdata/ServiceRequestServiceTemplate.json') * replace ServiceRequestPostTemplate | token | value | | assetId | assetTblAssetId | | country | country | | sourceSystemCode | sourceSystemCode | | serviceRequestCode | 'Karate-Insert: ' + NewServiceRequestCode |
Given path 'serviceRequests/' And request ServiceRequestPostTemplate
Error message in below attachment. Note, I checked the request manually through Swagger UI and everything worked fine. I also passed it in as a hard coded variable in Karate and it worked fine. However, something about using the 'table' feature seems to change the media type.
Upvotes: 1
Views: 1430
Reputation: 58058
The moment you use replace
the type is converted to string - and this is clearly mentioned in the documentation.
So you have two options: a) type-cast the result of the replace back to JSON b) set the Content-Type
header manually.
Hope that helps !
Upvotes: 1
Reputation: 33
You need to add the content type as well by using header keyword as below
Given path 'some/path'
And request { some: 'data' }
And header Accept = 'application/json'
When method post
Then status 200
Hope this helps.
Upvotes: 2