How to specify Access Token in PostMan - json

I have imported a JSON file in to postman and the JSON Body is requesting Authorization Bearer value for a specific parameter. How to set a value to the parameter. Currently its undefined. Please refer the below JSON code and image.
"name": "Pos_TC-Name",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"tests[\"Status code is 200\"] = responseCode.code === 200;"
]
}
}
],
"request": {
"url": "http://localhost:52586/api/Patient/7",
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json",
"description": ""
},
{
"key": "Authorization",
"value": "Bearer {{NurseAdminToken}}",
"description": ""
}
],
"body": {
"mode": "raw",
"raw": ""
},
"description": ""
},
"response": []
},

You have to define the variable as a global under Manage Environments You click on the "Settings Wheel" top right half of the window. Then you select/switch to the environment where you defined the global (the drop down menu next to the setting wheel).

Related

Integromat - Dynamically render spec of a collection from an rpc

I am trying to dynamically render a spec (Specification) of a collection from an RPC. Can't get it to work. Here I have attached the code of both 'module->mappable parameters' and the 'remote procedure->communication' here.
module -> mappable parameters
[
{
"name": "birdId",
"type": "select",
"label": "Bird Name",
"required": true,
"options": {
"store": "rpc://selectbird",
"nested": [
{
"name": "variables",
"type": "collection",
"label": "Bird Variables",
"spec": [
"rpc://birdVariables"
]
}
]
}
}
]
remote procedure -> communication
{
"url": "/bird/get-variables",
"method": "POST",
"body": {
"birdId": "{{parameters.birdId}}"
},
"headers": {
"Authorization": "Apikey {{connection.apikey}}"
},
"response": {
"iterate":{
"container": "{{body.data}}"
},
"output": {
"name": "{{item.name}}",
"label": "{{item.label}}",
"type": "{{item.type}}"
}
}
}
Thanks in advance.
Just tried the following and it worked. According to Integromat's Docs you can use the wrapper directive for the rpc like so:
{
"url": "/bird/get-variables",
"method": "POST",
"body": {
"birdId": "{{parameters.birdId}}"
},
"headers": {
"Authorization": "Apikey {{connection.apikey}}"
},
"response": {
"iterate":"{{body.data}}",
"output": {
"name": "{{item.name}}",
"label": "{{item.label}}",
"type": "{{item.type}}"
},
"wrapper": [{
"name": "variables",
"type": "collection",
"label": "Bird Variables",
"spec": "{{output}}"
}]
}
}
Your mappable parameters would then look like:
[
{
"name": "birdId",
"type": "select",
"label": "Bird Name",
"required": true,
"options": {
"store": "rpc://selectbird",
"nested": "rpc://birdVariables"
}
}
]
Needing this myself. Pulling in custom fields that have different types but would like them all to show for the user to update customs fields or when creating a contact be able to update them. Not sure if best to have them all show or have a select drop down then let the user use the map for more than one.
Here is my response from a Get for custom fields. Could you show how my code should look. Got little confused as usualy look for add a value in the output and do you need two separate RPC's in integromat? Noticed your store and nested were different.
{
"customFields": [
{
"id": "5sCdYXDx5QBau2m2BxXC",
"name": "Your Experience",
"fieldKey": "contact.your_experience",
"dataType": "LARGE_TEXT",
"position": 0
},
{
"id": "RdrFtK2hIzJLmuwgBtAr",
"name": "Assisted by",
"fieldKey": "contact.assisted_by",
"dataType": "MULTIPLE_OPTIONS",
"position": 0,
"picklistOptions": [
"Tom",
"Jill",
"Rick"
]
},
{
"id": "uyjmfZwo0PCDJKg2uqrt",
"name": "Is contacted",
"fieldKey": "contact.is_contacted",
"dataType": "CHECKBOX",
"position": 0,
"picklistOptions": [
"I would like to be contacted"
]
}
]
}

Use JSON schema check on POST request with WireMock

I'm using WireMock (Docker) docker.io/rodolpheche/wiremock:2.27.2-alpine. I set it up via Docker Compose and everything works flawlessly.
I'm trying to set up a stub/mapping to check the JSON input against the corresponding JSON schema. Basically, this is the stub/mapping:
{
"name": "Create Character Stub",
"request": {
"headers": {
"accept": {
"caseInsensitive": true,
"equalTo": "application/json"
},
"content-type": {
"caseInsensitive": true,
"equalTo": "application/json"
}
},
"method": "POST",
"url": "/api/characters",
"body": {
// [start] I made this up, but that's what I'm trying to achieve
"type": "JSON_SCHEMA",
"location": ""schemas/create-character.json""
// [end]
}
},
"response": {
"headers": {
"location": "{{ request.path }}/{{ randomValue type='UUID' }}"
},
"status": 201,
"transformers": ["response-template"]
}
}
...and this is (an excerpt of) the JSON schema:
{
"$schema": "http://json-schema.org/draft/2019-09/schema#",
"type": "object",
"description": "Character entity",
"properties": {
"first_name": {
"type": "string",
"description": ""
},
"last_name": {
"type": "string",
"description": ""
},
"age": {
"type": "number",
"description": ""
}
},
"additionalProperties": false,
"required": ["first_name", "last_name", "age"]
}
Is there a way to accomplish this with WireMock? I've been searching for something like that for a while. The closer I've found is to use JSON path, but that's not quite the same as checking for a proper schema — and could be tedious task with long JSON requests.
I searched through the issues in the WireMock's GitHub repository, but I can only see this one (closed by the way). Still, I don't see a way to do exactly what I'm looking for. I just have as input a JSON schema.

make requestBody fields optional in swaggerUI

Using the following versions for my flask python project:
connexion==2.3.0
swagger-ui-bundle==0.0.5
OAS 3.0
I want to make all the requestBody fields optional, right now I have defined the json as shown below and I have assumed if you do not provide required field in the requestBody, then it should be taken as false and if I do not provide any values in swagger UI for these fields it should NOT generate curl request with those fields with -d option.
"openapi": "3.0.0",
"info": {
"description": "Dev",
"version": "1.0.0",
"title": "DEV-API",
"contact": {
"email": "dev#email.com"
},
"license": {
"name": "Dev",
"url": "https://opensource.org/licenses/MIT"
}
},
"servers": [
{
"url": "http://xx.yy.zz.a:8080"
}
],
"tags": [
{
"name": "Custom Event Post Request",
"description": "Example API for posting custom events"
}
],
"paths": {
"/api/v1/calls/{id}/{event-name}": {
"post": {
"tags": [
"Post Event"
],
"summary": "Post Custom Event to a call",
"operationId": "post_call_custom_event_data",
"parameters": [
{
"name": "id",
"in": "path",
"schema": {
"type": "string"
},
"required": true
},
{
"name": "event-name",
"in": "path",
"schema": {
"type": "string"
},
"required": true
}
],
"requestBody": {
"content": {
"application/x-www-form-urlencoded":{
"schema": {
"type": "object",
"properties": {
"event1": {
"type":"boolean"
},
"event2":{
"type": "string"
},
"event3": {
"type":"string"
}
}
},
"encoding": {
"event2": {
"allowReserved": true
},
"event3": {
"allowReserved": true
}
}
}
}
},
"responses": {
"200": {
"description": "ok"
},
"400": {
"description": "Failed. Bad Post Data"
}
}
}
}
}
But it does generate with no Values as follows:
curl -X POST "http://xx.yy.zz.a:8080/api/v1/calls/5454/custom-event" -H "accept: /" -H "Content-Type: application/x-www-form-urlencoded" -d "event1=&event2=&document="
I am not sure how to make the requestBody fields/elements to appear as optional in swagger UI
Your API definition is correct. It's a limitation of Swagger UI that it always sends all form fields, including optional fields with empty values. This issue is tracked here:
https://github.com/swagger-api/swagger-ui/issues/5303

Bluemix WorkLoad Scheduler Process creation REST API does not accept queryparameters and headers in restfulstep

I am using the Bluemix Workload Scheduler REST API to create Processes with a Scheduled Trigger having a oneTimeProperty and a startDate.
Additionally the json i am sending also has a restfulStep.
The issue i have is, that no matter how i provide the "queryParameters" and "headers" for the restfulStep, they are not accepted/configured in the process after the successful process creation.
Here is the json i am using:
{
"name": "my process name",
"processlibraryid": 1234,
"processstatus": true,
"triggers": [
{
"name": "Scheduled Trigger",
"triggerType": "OnceTrigger",
"oneTimeProperty": {
"startDate": "TIMEVALUE"
}
}
],
"steps": [
{
"restfulStep": {
"agent": "AGENTNAME}",
"action": {
"uri": "MYCUSTOMURL",
"contentType": "application/json",
"method": "POST",
"verifyHostname": true,
"queryParameters": [
["param1", "value1"],
["param2", "value2"]
],
"headers": [
["param3", "param4"]
],
"numberOfRetries": 3,
"retryIntervalSeconds": 30
},
"authdata": {
"username": "USERNAME",
"password": "PASSWORD"
},
"input": {
"input": "",
"isFile": false
}
}
}
]
}
issue has been fixed with last Workload Scheduler upgrade.
Could you try using a Json like the following?
{
"name": "myname",
"processlibraryid": <1234>,
"processstatus": false,
"triggers": [
{
"name": "Scheduled Trigger",
"triggerType": "OnceTrigger",
"oneTimeProperty": {
"startDate": "2016-12-16T10:30:43.218Z"
}
}
],
"steps": [
{
"restfulStep": {
"agent": "<MY_AGENT_NAME>",
"action": {
"uri": "<MY_URL>",
"contentType": "application/json",
"method": "GET",
"verifyHostname": true,
"queryParameters": [
["param1", "value1"],
["param2", "value2"]
],
"headers": [
["Accept", "application/json"],
["User-Agent", "Mozilla/5.0 "]
],
"numberOfRetries": 3,
"retryIntervalSeconds": 30
},
"authdata": {
"username": "USERNAME",
"password": "PASSWORD"
},
"input": {
"input": "",
"isFile": false
}
}
}
]
}
Regards
Andrea I
your json is correct but there is a little bug in Workload Scheduler service.
A fix will be released by the end of December.
As workaround, you could use Application Lab in order to create your Restful step. In addition, you could append the queryParameters to your uri address.
At the moment, there is no workarounds for headers.
If you find other issue using the service, do not hesitate to post your comments.
Thanks!
Andrea I

Swagger UI returns "no content" in the Response Body, and Response Code 0

I'm newer to Swagger UI. I use swagger with Json. When the response is also Json. When clicking Try it Out, I see a correct Request URL, but the Swagger UI returns "no content" in the Response Body, and Response Code 0.
Mentioned that API's URL is not publicly accessible, but the site that hosts the Swagger UI is in the same network as the site that hosts the API.
I see this stack overflow question, but not found the solution.
My Swagger.Json file:
{
"swagger": "2.0",
"info": {
"version": "1.0.0",
"title": "Swagger for Rest API",
"description": "A sample API that uses a application as an example to demonstrate features in the swagger-2.0 specification",
"termsOfService": "http://helloreverb.com/terms/",
"contact": {
"name": "Swagger API team",
"email": "abc#gmail.com",
"url": "http://xxxx.com"
},
"license": {
"name": "MIT",
"url": "http://opensource.org/licenses/MIT"
}
},
"host": "localhost:85xx",
"basePath": "/v1",
"schemes": [
"http"
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"paths": {
"/test/{username}/{albumname}/{imagename}": {
"get": {
"description": "Returns all images from the system that the user has access to",
"operationId": "findface",
"produces": [
"application/json",
"application/xml"
],
"parameters": [
{
"name": "username",
"in": "path",
"description": "tags to filter by",
"required": true,
"type": "string"
},
{
"name": "albumname",
"in": "path",
"description": "maximum number of results to return",
"required": true,
"type": "string"
},
{
"name": "imagename",
"in": "path",
"description": "maximum number of results to return",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/test1"
}
}
},
"default": {
"description": "unexpected error",
"schema": {
"$ref": "#/definitions/errorModel"
}
}
}
}
}
},
"definitions": {
"test1": {
"type": "object",
"required": [
"id",
"name"
],
"properties": {
"id": {
"type": "integer",
"format": "int64"
},
"name": {
"type": "string"
},
"tag": {
"type": "string"
}
}
},
"errorModel": {
"type": "object",
"required": [
"code",
"message"
],
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
Please can any one help.
Thank in Advance.
It should be a CORS issue. You should add Access-Control-Allow-Origin: * into response headers.
Please refer: https://github.com/swagger-api/swagger-ui/blob/master/README.md#cors-support
It should be a CORS issue. You should add Access-Control-Allow-Origin: * into response headers.
Use this code in the startup class
// global cors policy
app.UseCors(x => x
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());