Include default responses to swagger documentation - rest

I am building an application using swagger in python. I specified all outcomes produces by my code in the swagger yaml file. Connexion, the library which I am using, also checks for validity of the data provided by the client and might for example return
{
"detail": "Invalid Content-type (application/json), expected JSON data",
"status": 415,
"title": "Unsupported Media Type",
"type": "about:blank"
}
For the documentation to be complete the ui should consists of all the response messages specified by me and the implicit response messages of connexion.
Is there a way to add all this implicit responses to the swagger-ui?

Related

What is the expected request to get GoToWebinar webinar details based on organiser_key?

I am trying to fetch GoToWebinar details via the
Get Webinars method
​/organizers​/{organizerKey}​/webinars
listed on the GoToWebinar API reference.
I'm passing the below body:
{
"fromTime":"2015-07-13T10:00:00Z",
"toTime":"2015-07-13T22:00:00Z"
}
But in response, I get the below error:
{
"errorId": "26a9b9a8-3a92-45b0-acdd-7ac3c3f485ac",
"requestId": null,
"timeStamp": 1587960550357,
"reason": "invalid.data",
"errorCode": "invalid.data",
**"description": "Required DateTime parameter 'fromTime' is not present",**
"incident": "5801952841989547523",
"details": null
}
The API reference guide does not specify any request structure, just mentions what is needed to be sent, and I have built my logic on the same. Yet I am unable to get a proper response.
Can anybody help me in understanding what the expected request should be?
Since this is a GET HTTP call you can not add these parameters to the Body. I mean you can but it won't be sent along with the call (only with POST/PUT). So you should add the two fields you provided to the Query Parameters instead.

How to make a basic HTTP request with API key in Google Translate API v2?

I want to make a translation with Google Translate API v2 with a basic HTTP request. I get an API key from the console but I can't find out how to use arguments to make the translation.
Note: I want it to autodetect the source language and I only want to choose the target language.
This is the URL that I tried to use:
https://translation.googleapis.com/language/translate/v2/detect?fields=detections&key=BIzaSyA8uHGnsA8ICcBWWJcxhqVePGFMq0L4u0g&q=grapes&target=es
It returns this:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"errors": [
{
"message": "Request contains an invalid argument.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
See the documentation.
The authentication token goes in the Authorization request header, not the query string.

How can I include JSON body API examples in Swagger2Markup API requirements (when converting from Swagger YAML)?

I've used the Swagger editor (editor.swagger.io) to create API requirements that look great online in a web browser, but I want to convert this Swagger YAML documentation into a format that can be printed (Word, PDF, Excel, HTML) and read offline.
The only way I've seen to convert the Swagger YAML into a clean, printable API requirements document is using the Swagger2Markup CLI (here's the reference documentation: http://swagger2markup.github.io/swagger2markup/1.3.3/ - Chapter 8 describes the CLI), then converting this adoc format to HTML from AsciiDoctor. The final product is very readable as you can see from the Swagger2Markup reference documentation.
However, unfortunately, the final Swagger2Markup documentation of an API doesn't include JSON or xml examples of the API body, which is arguably the most important part of the documentation in my opinion! For example, in the Swagger editor's petstore, this would be the json body example for the POST /pet API:
{
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "doggie",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
But this JSON example isn't included in the Swagger2Markup documentation.
So my question is, is it possible to update Swagger2Markup (or change the Swagger2Markup properties) to include JSON body API examples in the final document?
If not, is there a different way you recommend converting Swagger YAML into a readable document that includes JSON body API examples?
To add json body API examples to the adoc with swagger2markup, create a config file (config.properties) and add "swagger2markup.generatedExamplesEnabled=TRUE". Per the swagger2markup reference document, section 3.2.5, this property specifies if http rquest and response examples should be generated. Awesome!

Facebook's Batch Request not picking up a JSON parameter

My goal is to create a number of ads using Facebook's Batch API : https://developers.facebook.com/docs/marketing-api/asyncrequests/v2.9
I am sending a POST request at this URL:
https://graph.facebook.com/v2.9/act_158365238/ads
I am sending 2 parameters as per the documentation:
1- access_token
2- batch
The JSON in the batch parameter looks like :
{
"method": "POST",
"relative_url": "v2.9\/act_158365238\/ads",
"attached_files": "test1",
"body": "creative={\"title\":\"Test title 1\",\"body\":\"Test body 1\",\"object_url\":\"https:\/\/apps.facebook.com\/testapp\/\", \"image_file\":\"test1.jpg\"}&targeting={\"countries\":[\"US\"]}&name=test1"
}
The Problem
When I send this request with POSTman or my PHP code, it throws the following error
{
"error": {
"message": "(#100) The parameter creative is required",
"type": "OAuthException",
"code": 100,
"fbtrace_id": "Gj2sG7N8l1f"
}
}
However when I send the exact same request via Facebook's Graph API tool, it successfully creates the ads.
According to the API Documentation provided to create creatives you should be posting to the URL "v2.9/act_187687683/adcreatives"... The fragment of the batch that you are showing is used to create an Ad.
If, as you say, your intention is to create an AdCreative then you should be using something like the above, which differs in the body from what you are using:
{
"method": "POST",
"name": "create_creative",
"relative_url": "v2.9/act_187687683/adcreatives",
"attached_files": "test1",
"body": "title=Test title&body=Test body&link_url=http://www.test12345.com&image_file=test1.jpg"
}
In the other hand, if what you are creating is an add, then you should consider referencing the AdCreative by its ID as is done in the examples, hence in the case of a creative added in the same batch you could use the relative reference to the name:
creative={\"creative_id\":\"{result=create_creative:$.id}\"}
or if it is a creative already created you can reference it by the creative_id:
creative={\"creative_id\":\"123456\"}
I think the message is a red herring -- it's not seeing your body's creative field because the OAuth isn't properly set in your POSTman requests, so it isn't parsing the body or seeing the creative field.
If you don't know how to set OAuth in POSTman, here's a good tutorial:
https://docs.brightcove.com/en/video-cloud/concepts/postman/postman.html

Eloqua bulk REST API gives serialization error

I am trying to make bulk REST API call to import data to Eloqua. I am able to make call to GET, But POST gives me "400- There was a Serialization Error".
This is first step to get response for creating import definition from Eloqua Bulk REST.
URL: /api/bulk/2.0/contacts/imports
Headers:
Authorization: valid oAuth2 token
Content-Type: application/json
Body:
{
"name": "AppSource Test",
"fields": {
"firstName": "{{Contact.Field(C_FirstName)}}",
"lastName": "{{Contact.Field(C_LastName)}}",
"emailAddress": "{{Contact.Field(C_EmailAddress)}}"
},
"identifierFieldName": "emailAddress"
}
Documentation also doesn't have details about this.
Am I missing something?
Change Body content type to "raw"
Explanation:
Eloqua expects the data it receives be in "raw" format. Although Header says Content type json, Setting Body as "raw" works.