Postman json payload with variable from environment variables is not working - environment-variables

I have the next json payload:
{
"action": "created",
"installation": {
"id": {{installationId}}
}
}
I have created an environment and defined the installationId variable but it seems like is not working, because I am using this payload to build a hmacSignature, which I send in the Headers, something like:
var hmacSignature =CryptoJS.HmacSHA256(request.data, 'keySecret').toString(CryptoJS.digest);
postman.setEnvironmentVariable("hmacSinature", "sha256=" + hmacSignature);
But when I use the environment variable it is not working.
In the pre-request-script I use the next command:
console.log("request1:", request.data)
and I got: request1:
{
"action": "created",
"installation": {
"id": {{installationId}}
}
}
It seems like the value is not replaced by the one from the Postman env variables.
Any ideas?

Related

Krakend endpoint variable within extra config

I have to use an endpoint variable within extra-config Proxy Flatmap Filter arguments.
...
{
"endpoint": "/cascade/{entity}/{id}/{subentity}/{commonField}",
"backend": [
{
"url_pattern": "/api/{entity}/{id}",
"host": ["http://myapi:8080/"],
"encoding": "json",
"extra_config": {
"proxy": {
"flatmap_filter": [
{
"type": "move",
"args": ["{{commonField}}","customField"]
}
]
}
}
}
]
}
...
I need to get from url commonField and use it within flatmap filter as first value of args array.
But this doesn't work. Is a kind of configuration constraint that I can't use URL variable anyware in the configs?
Although using variables from url_pattern in flatmap_filter is not possible out-of-the-box currently, you can always use Lua scripting or a request/response modifier plugin (using Golang) to achieve that transformations.

Can't place GraphQL custom type as a Postman variable

Has anyone had luck with placing a GraphQL custom type argument as a Postman or Graphql variable? I'm kinda spinning in circles right now, I hope a fresh pair of eyes could point me in the right direction.
What I'm trying to do is to send a mutation request using Postman. The problem I'm having is that the method I'm calling is taking a custom type as an argument. Placing the content of that variable as GraphQL variable or Postman variable is giving me a headache. I can't embedd pictures yet, so here are the links (they are safe).
Schema
This custom type is a JSON-like structure, consisting of two enums and a set of primitive types (strings, ints...). I can screenshot the entire thing but basically that's it: two enums followed by strings, ints...
Custom type definition
What I've tried so far:
Simply hardcoding the request in Postman works but I wish to send multiple requests with varying data
Placing it in a GraphQL variable results in error message
{
"errors": [
{
"message": "Bad request - invalid request body.",
"locations": []
}
],
"data": null
}
Placing the custom type content as a Postman environment variable works, but I'm getting a syntax error (although the request passes...).
Request body is below. Hardcoding it and using a Postman variable produces the same request body, apart from the syntax error.
query: "mutation {
createApplication(request: {
applicationKind: NEW_ISSUANCE,
documentKind: REGULAR_PASSPORT,
personalData: {
timestamp: null,
firstname: "NAME",
lastname: "LASTNAME",
middlename: "MIDDLENAME",
dateOfBirth: "2011-09-28",
citizenshipCountryCode: "USA",
gender: MALE,
personalNumber: "3344",
placeOfBirth: "CHICAGO",
municipalityOfBirth: "SOUTH",
countryCodeOfBirth: "USA"},
addressData:{
street: "WEST",
municipality: "EAST",
place: "CHICAGO",
country: {
code: "USA",
name: null
},
entrance: "б",
flat: "13",
number: "35"}
})
{
__typename
... on AsyncTaskStatus {
taskID
state
payload {
... on ApplicationUpdated {
applicationID
applicationNumber
__typename
}
__typename
}
__typename
}
... on Error {
...errorData
__typename
}
}
}
fragment errorData on Error {
__typename
code
message
}"
Postman variable with a squiggly line
I'm spinning in circles right now. Has anyone had any luck with Postman requests of this kind?
I can post more info, screenshots...just let me know. I'll be watching this topic closely and provide feedback.
Thank you for your time.
please add a the variable in variable section as :
{
"request": {{request}}
}
and then refer this in your query as
$request

How to write swagger API document for an API that has only 1 post endpoint?

I have a web server that exposes an interface to external application.
All methods are sent as POST requests(read as well as write/update).
There is only ONE endpoint URL for accessing all the
methods("/serve"). Inside the POST body there is a property called
"function" which defines the method name to be called.
How do I document the API of this server in swagger. An example doing similar stuff will be appreciated.
For example: Here is the sample body of a POST request:
endpoint URL: https://test-web-service.example.com/serve
type: POST
Body:
getCustomerById
{
"function": "getCustomerById",
"args":
["CUST00001"]
}
getAllCustomers
{
"function": "getAllCustomers",
"args":
[]
}
createCustomer
{
"function": "createCustomer",
"args":
["CUST001","MAC","mailto:mac#example.com","PO Box 39100, Howick"]
}
updateCustomer
{
"function": "updateCustomer",
"args":
["CUST001","MAC OWENS","mailto:mac#example.com","PO Box 39100, Howick"]
}
Thanks!

How to retrieve data from response body when using trigger URL

I am using trigger URL to run a test case created on Runscope. In response I am getting only details as shown in Runscope documentation. For eg.
Response Sample data:
{
"data": [],
"error": null,
"meta": {"status": "success"}
}
But I need the data in response body retrieved from server for request made.For eg.
{
"Status": "OK",
"Body": [{"userId": 12345,"sessionId": "abcd:1234"}]
}
I am using HttpRequest and HttpResponse for the same.
Why don't you use something like this :
https://www.npmjs.com/package/dyson#installation
It is used to mock results via api .

Default datatype mapping in elasticsearch

The following are the contents of config/default_mapping.json:
{
"_default_" : [
{
"int_template" : {
"match": "*",
"match_mapping_type": "int",
"mapping": {
"type": "string"
}
}
]
}
Want i want ES to do is to pick out all numbers from my logs and map them as strings.
Use case-
After clearing all indexes- curl -XDELETE 'http://localhost:9200/_all', i run this to send the following to ES (through fluentd's tailf plugin)-
echo "{\"this\" : 134}" >> /home/user/logs/program-data/logs/tiger/tiger.log
Elastic happily creates the initial indexes. Now, to test weather my default_mapping works, i send a string at the value where i previously sent an int.
echo "{\"this\" : \"ABC\"}" >> /home/user/logs/program-data/logs/tiger/tiger.log
Exception caught by ES-
org.elasticsearch.index.mapper.MapperParsingException: failed to parse [this]
at org.elasticsearch.index.mapper.core.AbstractFieldMapper.parse(AbstractFieldMapper.java:398)
at org.elasticsearch.index.mapper.object.ObjectMapper.serializeValue(ObjectMapper.java:618)
at org.elasticsearch.index.mapper.object.ObjectMapper.parse(ObjectMapper.java:471)
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:513)
at org.elasticsearch.index.mapper.DocumentMapper.parse(DocumentMapper.java:457)
at org.elasticsearch.index.shard.service.InternalIndexShard.prepareCreate(InternalIndexShard.java:342)
at org.elasticsearch.action.bulk.TransportShardBulkAction.shardIndexOperation(TransportShardBulkAction.java:401)
at org.elasticsearch.action.bulk.TransportShardBulkAction.shardOperationOnPrimary(TransportShardBulkAction.java:155)
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction.performOnPrimary(TransportShardReplicationOperationAction.java:556)
at org.elasticsearch.action.support.replication.TransportShardReplicationOperationAction$AsyncShardOperationAction$1.run(TransportShardReplicationOperationAction.java:426)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:701)
Caused by: java.lang.NumberFormatException: For input string: "ABC"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:438)
at java.lang.Long.parseLong(Long.java:478)
at org.elasticsearch.common.xcontent.support.AbstractXContentParser.longValue(AbstractXContentParser.java:89)
What could be wrong here?
Update-
My default_mapping.json now looks like-
{
"_default_": {
"dynamic_templates": [
{
"string_template": {
"match": "*",
"mapping": {
"type": "string"
}
}
}
]
}
}
First of all, I'd suggest not to use file system based configuration or mappings. Just do it via api.
Your mapping is malformed, as you have the type name (_default_) but you don't specify that what you are submitting is a dynamic template.
As for the content, I'd remove that match_mapping_type if you want to map everything as a string.

Resources