Karate API -> JSON Request -> Base field in JSON not being sent in request (works in Postman) - karate

My JSON request has a base value that is the top object.
Sample:
{
"partner_id": "6f4a3092-1b11-48c0-8a11-ae455b327ed8",
"borrowers": [
{
"loan": {
"loan_number": "89898989898222",
The partner_id is not being sent with the rest of the request.
Does this first object require special treatment to be sent with the rest of the request?
It feels like it should 'just work'

In my steps to file a bug, it started working in picking up the base object.

Related

How to use a mail template ID when sending an email with admin api in shopware 6?

When sending an email via Shopware 6 admin api (https://shopware.stoplight.io/docs/admin-api/b3A6MTI2MjUzOTg-send-a-mail) i would like to pass only the mail template ID, and not the other information from the template (contentHtml, contentPlain, subject).
Do you know if this is possible ?
This endpoint was not implemented to fetch an existing mail_template entity by an id. You'll have to provide the mails content yourself.
Your best bet would be to send a request to the corresponding endpoint for mail templates, e.g. GET /api/mail-template/086f8adc94f14a618e3729d933befb8d, and retrieve the values for subject, contentHtml and contentPlain from the response. These will still be un-rendered Twig at that point. So there should be no problem in passing them with your POST /api/_action/mail-template/send request. Just remember that you have to provide the data for the variables used in the templates. It looks like this isn't documented, but you need to provide the data in the request body with the key mailTemplateData.
So as an example see this abbreviated request body:
{
"contentPlain": "Hello {{ user.firstName }}!", // retrieved by `/api/mail-template/:id`
"mailTemplateData": {
"user": {
"firstName": "Pete"
}
}
}

Ktor returns 415 from endpoints where receive() is used with ContentNegotiation

I have parameter classes with the #Searializable annotation:
#Serializable
data class ShowPostURL(
val date: String,
val titleSlug: String,
override val redirectTo: String? = null
)
and no matter what I do call.receive() won't work. I'm getting HTTP 415 errors and Ktor doesn't log anything. I've added the serialization support as well:
install(ContentNegotiation) {
json()
}
How do I fix this? This is how I'm trying to use it:
accept(ContentType.Any) {
get("/foo/{date}/{titleSlug}") {
val input = call.receive(ShowPostURL::class)
call.respondText("foo")
}
}
If I do a trace I can see that my route is matched, but it can't receive the parameters. Is this json() setup is supposed to work when I'm deserializing from url parameters like this?
Firstly, ContentNegotiation feature works only for receiving custom objects from the payload of POST, PUT and PATCH requests:
POST, PUT and PATCH requests have an associated request body (the payload). That payload is usually encoded.
In order to receive custom objects from the payload, you have to use the ContentNegotiation feature. This is useful for example to receive and send JSON payloads in REST APIs.
When receiving, the Content-Type of the request will be used to determine which ContentConverter will be used to process that request
Secondly, there are three out of the box ContentConverter available:
GsonConverter, JacksonConverter and SerializationConverter.
Each of these converters has its own configuration function: gson, jackson and serialization respectively. You use json configuration function which is most likely is not appropriate for the configuration of ContentNegotiation.
To solve your problem you can access URL parameters by referring them with call.parameters and manually create ShowPostURL object. Then serialize it with the kotlinx.serialization framework if needed.
Also, you can write your own ContentConverter to implement custom logic for receiving typed objects.

How to get AWS API Gateway to validate JSON Body against Model

The newly released "x-amazon-apigateway-request-validator" (in April I believe) is supposed to be able to run a JSON schema validation against the POST/PUT payload of an API.
I've tried to implement this in several different ways now but I can't make it work...
I have added the validators:
"x-amazon-apigateway-request-validators": {
"ValidateBody": {
"validateRequestParameters": false,
"validateRequestBody": true
},
"ValidateHeaders": {
"validateRequestParameters": true,
"validateRequestBody": false
}
}
For any methind I will look for specific headers so I also have the parameters in the "root" of the Swagger:
"x-amazon-apigateway-request-validator": "ValidateHeaders"
In the POST I have a x-amazon-apigateway-request-validator: ValidateBody and then a Model with the JSON schema where several elements are required.
I can however POST anything as long as it is JSON... There is no validation against the JSON schema done...
What am I missing?
It is working!
There is a time lag between the deploy and the actual usage of the new code even though I am not doing any caching it seems.
Went out for lunch and came back to a working solution!
{
"message": "Invalid request body"
}
It would be nice to be able to modify the response message though...

ShopStyle API - How to Invoke an HTTP request

How do I Invoke an HTTP request with a particular URL and process the body of the response as XML?
Information Provided by ShopStyle:
HOW TO USE THE API:
Choose the method that returns the data your application needs. For example, the /products method is used to get products that match a given category or brand.Construct a URL for that method with the appropriate host, method name, and query parameters. Invoke the URL as an HTTP GET.
When the HTTP response arrives, extract the required data elements from the response's body.The rest of this document describes the details of constructing the right URL for each of the API methods. The XML format of the responses may be seen by clicking on the sample URLs shown for each method. The responses in JSON format contain identical information, just in a different format.
SHOPSTYLE API URLS
All ShopStyle API URLs have the following form:
http://api.shopstyle.com/api/VERSION/METHOD_NAMEpid=YOUR_API_KEY&format=FORMAT&...
The METHOD_NAME is taken from the list of methods in the various API shown at left (Press Link To View List of Methods-https://www.shopstylecollective.com/api/overview).
COMMON API PARAMETERS
All methods in the API accept these parameters:
API_KEY (my unique key is ******************)
pid Unique API_KEY string that is assigned to the caller. You can find your API Key on the Account Settings page.
FORMAT
The format of the response. Supported values are:
json - The response is in JSON format with UTF-8 encoding. This is the default if the parameter is absent.
xml - The response is in XML format with UTF-8 encoding.
jsonp - The response is in JSON format with UTF-8 encoding wrapped in a JavaScript method called padding. The padding must be specified with the query parameter 'callback'. Only single expressions (function reference, or object property function reference) are accepted as valid padding.
When set to 1 or 'true' the HTTP status will always be 200. Use the field "errorCode" in the response to detect whether the API Call was successful. By default, when an error occur the HTTP Status of the response will be different than 200
Again I am a beginner, so please provide detailed information on how to retrieve CATEGORY data (Examples: Dresses, Tops, Buttoms, etc) in XML format.**
Thank you!!!
Here's a simple example to get your started. Copy the code below and put it into a file, say "cat.php". Then run it by typing "php cat.php" at a command prompt (assumes you have php on your machine):
<?php
// don't show dom parse errors
libxml_use_internal_errors(true);
// grab the xml from the api
$response = file_get_contents("http://api.shopstyle.com/api/v2/categories?pid=TEST&format=xml");
$doc = new DOMDocument();
$doc->loadHTML($response);
// grab all the categories
$elements = $doc->getElementsByTagName('categories');
foreach($elements as $node){
foreach($node->childNodes as $child) {
// get the name out of the category
$nodes = $child->getElementsByTagName("name");
foreach ($nodes as $name) {
echo $name->nodeValue . PHP_EOL;
}
}
}

File Upload with Additional Parameters as JSON

I am using the below code to upload image with some additional parameters.
[HttpPost]
public HttpResponseMessage Upload(Data data)
{
var count = HttpContext.Current.Request.Files.Count;
return null;
}
I tried checked this method using postman chrome extension. I passed these values
Under Headers
enctype: multipart/form-data
Content-Type: application/json
Under form-data added one image file
Under raw
{
"Id": "1",
"ModifiedBy" : "1"
}
But the problem i am getting 0 for count
The Content-Type should be multipart/form-data not application/json for your code to work. A typical content type looks like this:
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryvmxBBVAoH3KRsa9L
The actual post data then contains blocks of 'data' separated by the boundary. These blocks can contain a content type, but they don't have to. If you're doing file uploads the content type should not matter - the filename is what determines the type.
All that said, with WebAPI you shouldn't be using the ASP.NET HttpContext object, but rather the lower level Web API semantics. While what you're doing works as long as you run inside of the ASP.NET stack, if you self-host or maybe in the future run ontop of a different stack like OWin/Katana this code will no longer work.
To handle file uploads with Web API specific code check out this blog post from Filip W.
http://www.strathweb.com/2012/04/html5-drag-and-drop-asynchronous-multi-file-upload-with-asp-net-webapi/