Requirement -
User will hit an URL and a CSV is downloaded on calling machine.
Implementation
Below is my RAML (1.0) definition
/{format}:
is: [ genericErrorResponsesCompliant ]
get:
description: Get/Download list of all ACTIVE accounts in a given format (CSV/JSON) default is JSON
body:
application/json:
responses:
200:
body:
application/octet-stream:
202:
body:
application/json:
404:
body:
application/json:
example: !include resources/json/example/error/error-resource-not-found-response-example.json
ISSUE:
When request are sent using -
API-Console to invoke the API, a CSV response is seen
postman - I get UnsupportedMediaTypeException in Mule Console
postman (when Content-Type application/json is passed) CSV output is seen in the response section
browser I get the error UnsupportedMediaTypeException
Question
If i do not set the content-type then the API-Kit fails validation and an exception is sent. Is there a way where a default Content-Type is set as application/json and the end-user can access the url from the browser and the csv is downloaded?
I should be able to overcome Exception thrown by API-Kit
If you need any more information let me know, but I am struggling to get this done. Any help will be appreciated.
Exception
Root Exception stack trace:
org.mule.module.apikit.exception.UnsupportedMediaTypeException
at org.mule.module.apikit.HttpRestRequest.handleUnsupportedMediaType(HttpRestRequest.java:306)
at org.mule.module.apikit.HttpRestRequest.negotiateInputRepresentation(HttpRestRequest.java:300)
Environment
Mule 3.8 runtime on Studio version 6.1.1
It's because you have this for the GET request:
get:
description: Get/Download list of all ACTIVE accounts in a given format (CSV/JSON) default is JSON
body:
application/json:
Remove body: application/json there's no need for it on the GET request. It will then allow you invoke the API without a Content-type.
I wish if it worked.
Get the same exception. RAML after #ryan-carter suggestions
/{format}:
is: [ genericErrorResponsesCompliant ]
get:
description: Get list of all ACTIVE accounts for a given country in a given format (CSV/JSON) default is JSON
headers:
Content-Type:
default:
'*/*'
responses:
200:
body:
application/octet-stream:
Related
I am trying to perform patch operation using latest version of Karate with below,
Also I notice the special charater "/" in the payload is replaced by "/" in the report. Hoping that is not a issue as I tried sending the exact payload captured in report through postman and the request went through. Is there a way to avoid replacing that special characters, even after using charset UTF-8 and surefire plugin configuration?
Scenario: Test for PATCH METHOD
Given url URL
And request [{ "op":"replace","path":"/Package/Content/Application/OtherIncome/0/#Frequency","value":"Monthly"}]
And header Content-Type = 'application/json-patch+json; charset=utf-8'
And header Accept = 'application/json'
When method patch
Then status 200
Error:
00:19:07.042 java.lang.RuntimeException: java.io.EOFException, http call failed after 2575 milliseconds for url: https://apigateway.bbldtl.int/babl/int/dev/loan-application-api/v1/applications/22634247
00:19:07.042 classpath:loanApplicationApi/Patch/editIncome/editIncome.feature:15
When method patch
http call failed after 2575 milliseconds for url: https://apigateway.bbldtl.int/babl/int/dev/loan-application-api/v1/applications/22634247
classpath:loanApplicationApi/Patch/editIncome/editIncome.feature:15
I have a Swagger 2.0 file that has an auth mechanism defined but am getting errors that tell me that we aren't using it. The exact error message is “Security scheme was defined but never used”.
How do I make sure my endpoints are protected using the authentication I created? I have tried a bunch of different things but nothing seems to work.
I am not sure if the actual security scheme is defined, I think it is because we are using it in production.
I would really love to have some help with this as I am worried that our competitor might use this to their advantage and steal some of our data.
swagger: "2.0"
# basic info is basic
info:
version: 1.0.0
title: Das ERP
# host config info
# Added by API Auto Mocking Plugin
host: virtserver.swaggerhub.com
basePath: /rossja/whatchamacallit/1.0.0
#host: whatchamacallit.lebonboncroissant.com
#basePath: /v1
# always be schemin'
schemes:
- https
# we believe in security!
securityDefinitions:
api_key:
type: apiKey
name: api_key
in: header
description: API Key
# a maze of twisty passages all alike
paths:
/dt/invoicestatuses:
get:
tags:
- invoice
summary: Returns a list of invoice statuses
produces:
- application/json
operationId: listInvoiceStatuses
responses:
200:
description: OK
schema:
type: object
properties:
code:
type: integer
value:
type: string
securityDefinitions alone is not enough, this section defines available security schemes but does not apply them.
To actually apply a security scheme to your API, you need to add security requirements on the root level or to individual operations.
security:
- api_key: []
See the API Keys guide for details.
I'm currently working through the Mulesoft Mule 4 Fundamentals course and have deployed an application on Runtime Manager.
When I look in the logs of my application on Runtime Manager and the logs of Anypoint Studio I see the above "Unsupported Media Type" error when testing a GET HTTP request. I also get this error when testing in ARC.
When I look in the Mule debugger and then the payload in Anypoint Studio I see mediaType = */* charset = UTF-8
I thought that this does not need to be added for GET requests, so how do I get around this?
My RAML file:
#%RAML 1.0
title: session-2
types:
newsProperties: !include schemas/newsDataType.raml
/search:
get:
headers:
Accept:
default: application/json
queryParameters:
keyword:
type: string
minLength: 3
maxLength: 10
responses:
200:
body:
application/json:
example: !include examples/searchExample.raml
400:
body:
application/json:
example:
{"message": "Search query too long"}
/news:
post:
queryParameters:
country:
required: false
body:
application/json:
type: newsProperties
responses:
201:
body:
application/json:
example: !include examples/searchExample.raml
/sportsNews:
put:
body:
application/json:
type: newsProperties
The header in the /search resource GET method has been added recently after searching online and trying a number of different solutions I've seen, but I am still getting the same error. Any help would be appreciated.
Thanks!
I had this same problem and I solved it by mapping the endpoint on Router (apikit:config).
Then I figured out the name set to the router was different on the endpoint flow, like:
Flow name: get:(userId):api-config
Router name: users-api-config
Fixing the name on flow or mapping the method on router solve this problem
Probably you are not setting the Content-Type header to application/json and the API implementation is expecting it.
Hello try to include a json example instead a raml example:
!include examples/searchExample.raml convert it to include json example.
!include examples/searchExample.json
I followed the following link from swagger documentation to create swagger json for my rest api.
https://swagger.io/docs/specification/2-0/describing-request-body/
In my rest api, I have request body and http headers like Content-Type and Authorization that go along with the service request.
I was wondering if there is a way to include request body and http header information in the swagger json ? I don't see that information in the swagger docs.
The Content-Type header of requests and responses is defined by the consumes and produces keywords, respectively. They can be specified on the operation level or on the root level of the spec.
The Authorization header is defined using the securityDefinitions and security keywords. OpenAPI/Swagger 2.0 supports Basic authentication, API keys and OAuth 2.
Other headers can be defined as in: header parameters.
For example, if an operation POSTs JSON and uses Basic auth, you can describe it as follows:
swagger: '2.0'
...
securityDefinitions: # Authorization, part 1
basicAuth:
type: basic
paths:
/something:
post:
summary: POST some JSON
consumes:
- application/json # Request Content-Type
produces:
- application/json # Response Content-Type
security:
- basicAuth: [] # Authorization, part 2
parameters:
- in: body
name: body
required: true
schema:
$ref: '#/definitions/Something'
responses:
200:
description: OK
Relevant documentation:
MIME Types
Authentication
Describing Parameters
I am having trouble with browser showing save/download prompt for zip file on http endpoint wiht APIKit Router.
I have a sub flow that gets S3 object and sets payload to #[message.payload.getObjectContent] which works fine with http listener going straight to flow, but if using APIKit router browser returns nothing.
I think it might have something to do with my raml.
/GetPackage
get:
responses:
200:
description: Success
body:
200:
application/zip
I also read something about...
Content-Disposition: attachment;filename=file.zip
Some help/direction would be much appreciated
Tnx!
Figured out a solution. It wasn't enough just having application/zip in RAML.
Needed to set two properties in Flow (with Property component):
Content-Disposition: attachment;filename=filename.zip
Content-Type: application/zip
Configuration XML that I used:
<set-property propertyName="Content-Disposition" value="attachment;filename=filename.zip" doc:name="Content-Disposition"/>
<set-property propertyName="Content-Type" value="application/zip" doc:name="Content-Type"/>