insomnia error: using tabs can lead to unpredictable results - insomnia

i have documentation api that using insomnia designer and in the last 12000 lines i hadnt error like this
in all jsons as body or result this error may occurred
requestBody:
content:
application/json:
schema: # Request body contents
type: object
example:
{
"type": "national_card",
"data": "",
"mimetype": "image/jpeg"
}

in my case just need to remote a space here

Related

cakephp crud plugin return validation errors

When PATCHing to a record using the Crud plugin and Crud.Api listener, a successful PATCH returns a 200 OK with an empty data array in the response.
{
"success": true,
"data": []
}
When validation fails after a PATCH, a 422 Unprocessable Entity with the following response is returned:
{
"message": "A validation error occurred",
"url": "\/admin\/users\/edit\/4.json",
"code": 422,
"file": "\/app\/vendor\/friendsofcake\/crud\/src\/Listener\/ApiListener.php",
"line": 189
}
but I expected something like:
{
"success": false,
"data": [
"errors": [...]
]
}
https://crud.readthedocs.io/en/latest/listeners/api.html#http-put-edit
If success is false a HTTP response code of 422 will be returned,
along with a list of validation errors from the model in the data
property of the response body.
Does the plugin need to be configured to return the errors?
I'm not overly familiar with the Crud plugin, but that response looks like the default CakePHP exception renderer response, so I'd guess that you probably haven't configured your app to use the Crud exception renderer:
config/app.php
'Error' => [
'exceptionRenderer' => \Crud\Error\ExceptionRenderer::class,
// ...
],
Quote from the docs:
Note: However if you are using CakePHP 3.3+’s PSR7 middleware feature the exceptionRenderer config won’t be used and instead you will have to set the Error.exceptionRenderer config in config/app.php to 'Crud\Error\ExceptionRenderer' as following
See Crud Docs > Listeners > API > Exception handler

API gateway blocking requests with content in body

I'm trying to post a request through AWS API gateway with postman.
I have aws IAM on and it appears to be working. I can send a request with nothing in the body I get a 200 response back from my lambda function.
I would like to send a binary file in the body however whenever I add anything, form-data, raw or binary data to the body of the request I get this message:
{
"message": "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.\n\nThe Canonical String for this request should have been\n'POST\ ..."
}
I have tried adding
image/png and application/octect-stream to Binary Media Types
and also tried specifying a model with just one field in it and that doesn't work either.
Any help would be much appreciated. I tried posting on AWS forums but there is no "post", "ask a question" or "create" button to actually ask a question, so back to old trusty stackoverflow.
Cheers. Mitch.
Edit API gateway setup:
openapi: 3.0.1
info:
title: AlarmEndpoints
version: '2019-03-02T03:22:39Z'
servers:
- url: https://602wer34n1.execute-api.ap-southeast-2.amazonaws.com/{basePath}
variables:
basePath:
default: /dev
paths:
/alarm/message:
post:
responses:
'200':
description: 200 response
content:
application/json:
schema:
$ref: '#/components/schemas/Empty'
security:
- sigv4: [
]
x-amazon-apigateway-integration:
uri: arn:aws:apigateway:ap-southeast-2:lambda:path/2015-03-31/functions/arn:aws:lambda:ap-southeast-2:962000000000:function:alarm_message/invocations
responses:
default:
statusCode: '200'
passthroughBehavior: when_no_match
httpMethod: POST
contentHandling: CONVERT_TO_TEXT
type: aws
components:
schemas:
Empty:
title: Empty Schema
type: object
securitySchemes:
sigv4:
type: apiKey
name: Authorization
in: header
x-amazon-apigateway-authtype: awsSigv4
x-amazon-apigateway-policy:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
AWS: arn:aws:iam::962000000000:user/alarm_user
Action: execute-api:Invoke
Resource: arn:aws:execute-api:ap-southeast-2:962000000000:*/*/*
Lambda Function:
import json
import os
import boto3
def lambda_handler(event, context):
var = os.environ.get("a_variable")
return {
'statusCode': 200,
'body': json.dumps({'message': 'Hello from Lambda 2!',
'echo': event,
'data': var})
}

How to change query parameter name in swagger?

I am trying to get this url:
https://search.me/Search/api/search?map=%7B%22query%22:%22CSCI+250%22,%22rows%22:500,%22term%22:%222181%22,%22career%22:%22%22,%7D
without converting special characters to HEX to URL would be:
https://search.me/Search/api/search?map={query:CSCI-250,rows:500,term:2181,career:}
I know it is not possible to serialize special characters as hex in openapi 3.0.0, so I am fine with the full JSON in the query parameter.
Where the parameter is a JSON -> URI
The JSON is:
{
map: {
"query": "CSCI 250",
"rows": 500,
"term": 2181,
"career": ""
}
}
but swagger instead renders:
https://search.me/search/api/search?query=CSCI-250&rows=500&term=2181&career=
As you can see, special characters are then converted into HEX.
Below is my path. What exactly am I doing wrong?
paths:
/search:
get:
summary: Search
parameters:
- in: query
name: map
description: JSON for lookup
required: true
schema:
$ref: '#/components/schemas/QueryParams'
responses:
200:
description: Course search response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/QueryResults'
400:
description: Bad request

Vue-resource can't get response body when HTTP error 500

I'm trying to handle an HTTP 500 error using vue-resource (1.2.1) this way:
const resource = Vue.resource('items');
resource.get().then(
(response) => {
// Do something with response.body
},
(error) => {
// Do something with error.body,
// even if the HTTP status code is 500.
// But for now it's null...
}
);
There is nothing in error.body, while the actual server's response have something to say... And I really want to get this data to be displayed in a cool way for my app's users to be aware of what's going on (rather than opening dev tools and inspect network's response data).
Is there something I'm missing in Vue http config? Or maybe server-side, does my API needs to respond in a specific way? Or even respond special headers? Or, is it simply a limitation (or a bug) of vue-resource?
EDIT
Here is the content of error, picked from a console.log:
Response {
body: "",
bodyText: "",
headers: Headers…,
ok: false,
status: 0,
statusText: "",
url: "http://my.domain/items",
data: ""
}
And, the content of the actual server response (which I expected to be into error.body, but is not), picked from "network" tab in dev tools :
{
"success": false,
"error": {
"message":"this is the error message",
"details":[],
"stackTrace":[]
}
}

"Resource Not Found" message received when sending a query to Keen IO API

I am using Advanced REST Client tool to test a data pull from the Keen IO API, and think getting the request right, but not getting the data. Getting "resource not found" error. This can also be done via CURL.
Headers: Authorization:
Content-Type: application/json
actual request: GET /3.0/projects//queries/saved/Sponsorships/result HTTP/1.1
HOST: api.keen.io
authorization:
content-type: application/json
Base URL used: https://api.keen.io
Any ideas as to what may be doing wrong?
The saved query name is capitalized "Sponsorships". Make sure your saved query name is lower-cased, not camel or title-cased. To be sure that you are getting the correct saved query name.
Also, you may want to first obtain a list of all saved queries as a reference:
GET /3.0/projects/<project_name>/queries/saved HTTP/1.1
HOST: api.keen.io
authorization: <your_key>
content-type: application/json
You will get something like this:
[
{
"refresh_rate": 0,
"last_modified_date": "2016-12-20T01:09:54.355000+00:00",
"query_name": "",
"created_date": "2016-12-20T01:09:54.355000+00:00",
"query": {
"filters": [],
"latest": 100,
"analysis_type": "extraction",
"timezone": "UTC",
"timeframe": "this_30_days",
"event_collection": ""
},
"metadata": {
"visualization": {
"chart_type": "table"
},
"display_name": ""
},
"run_information": null
}
]
FWIW, I also have seen the "Resource not found" error when writing data to an event if the project is not correctly set up. For example, passing in the wrong project_id or write_key or if the project was deleted from your Keen.io account.