The following syntax:
### List Webhooks [GET /webhooks]
+ Request
+ Headers
Authorization: Bearer <API_KEY>
+ Response 200 (application/json)
+ Attributes (array[Webhook])
doesn't look like an array when it's rendered in Apiary. See below.
Did something change?
Have you tried the new Apiary Documentation renderer? Many issues with rendering Data Structures have been fixed on it. I just tried your example and it renders as expected. https://help.apiary.io/tools/interactive-documentation-v4/
Related
I'm working on a NiFi 1.15 flow where I have to send a request to a service that requires 2 pieces of form-data sent in a POST request as a multipart/form-data. The first part is a simple JSON object with a few parameters, while the second part is a CSV file. Here is an example of what I am trying to achieve.
Content-Type: multipart/form-data; boundary=1cf28ed799fe4325b8cd0637a67dc612
--1cf28ed799fe4325b8cd0637a67dc612
Content-Disposition: form-data; name="json"; filename="json"
{"Param1": "Value1","Param2": "Value2","Param3": true}
--1cf28ed799fe4325b8cd0637a67dc612
Content-Disposition: form-data; name="file"; filename="body.csv"
Field1,Field2,Field3,Field4,Field5
VALUE_FIELD_1,VALUE_FIELD_2,VALUE_FIELD_3,"Some value for field 4",VALUE_FIELD_5
--1cf28ed799fe4325b8cd0637a67dc612--
Another acceptable output would have the Content-Disposition lines empty.
Due to a few restrictions in the environment I am working on, I am not allowed to use scripting processors, such as ExecuteGroovyScript as suggested in another SO question.
Instead, I started creating a GenerateFlowFile -> InvokeHTTP flow. The GenerateFlowFile would output to a flow file a text similar to the one mentioned above. Here is the screenshot of the GenerateFlowFile.
The connected InvokeHTTP processor is configured to use the POST Http Method and to send headers (the Authorization header in my case) and Send Message Body is set to true. It also extracts the Content-Type from the flow file previsously generated attribute through a ${mime.type} function. You can see the details in the following screenshots.
Sadly, this does not work. The server responds with an "Unexpected end of MIME multipart stream. MIME multipart message is not complete." error.
After searching for a while in SO, I found another question describing what looks like a similar problem, but there they are getting a different error and is also posting parameters through a different method.
I am also aware about the blog post from Otto Fowler where he shows how InvokeHTTP supports POSTs with multipart/form-data. I did try this approach too, but did not manage to get it working. The service throws an error stating that NiFi does not send one of my post:form:parts.
Right now I am stuck and am not able to send that data. I did manage to write a simple Python script to test if the server is working properly and it is. For reference, here is the script:
import requests
server = 'https://targetserver.com'
#Authentication
result = requests.post(server + '/authentication',
{'grant_type': 'password',
'username': 'username',
'password': 'password'})
token = result.json()['access_token']
#Build the request
headers = {'Authorization': 'bearer ' + token}
json_data = '{"Param1": "Value1","Param2": "Value2","Param3": true}'
# First the JSON then the csv file.
files = {'json': json_data,
'file': open('body.csv', 'rb')}
result = requests.post(server + '/endpoint', headers = headers, files = files)
print(result.text)
Does anyone have a suggestion on how to get around this situation?
I am trying to create a webhook. I am brand new to Ruby, but am setting up a very simple practice server. Each time a new issue/ticket is created for one of my github repos, a POST request is made to a URL that I have setup to grab the payload. I am loosely following this tutorial.
I am able to access all the elements that are being posted in the actual payload/body using this code:
require 'sinatra'
require 'json'
post '/payload' do
request.body.rewind
payload_body = request.body.read
puts payload_body
How can I grab the contents of the header? I have been scrolling through documentation, but have had no luck. I tried accessing the header through response and request.headers and received this error: NoMethodError - undefined method `headers' for #<Sinatra::Request:0x0000000006de49e0>
Please let me know if I am missing something here. Thank you.
Here is an example of the headers from my POST request:
Request URL: http://505db39aa8ef.ngrok.io:
Request method: POST
Accept: */*
content-type: application/json
User-Agent: GitHub-Hookshot/cf3e7e0
X-GitHub-Delivery: 8d7fe080-ecc2-11ea-9b34-d35efaaf3885
X-GitHub-Event: issues
X-GitHub-Hook-ID: 245792914
X-GitHub-Hook-Installation-Target-ID: 279687508
X-GitHub-Hook-Installation-Target-Type: repository
X-Hub-Signature: sha1=ed12f9e7a31b08f9109557d6a9dd899ca85de9b5
request.get_header('HTTP_X_GITHUB_HOOK_INSTALLATION_TARGET_TYPE')
# or
request.env['HTTP_X_GITHUB_HOOK_INSTALLATION_TARGET_TYPE']
It is worth mentioning that,sinatra will process custom header:
add prefix HTTP_
capitalize every letter
gsub - to _
You can use request.env to access all headers.
For detail information about what variable will be added HTTP_ you can refer there
I've been working with the API Blueprint format for designing an API and have had a lot of fun working with it. When I was declaring my data structures I came upon a code reuse or model reuse issue.
According to the documentation when declaring a Response it has to be done like this:
For example:
+ Request 200 (application/json)
However when multiple people work on the document I don't want to instruct them what return code to use since we have them defined and they're numbers so people forget them. So to avoid having to go back and forth, instead I made this with the idea that I can use/reference one of the properties:
# Data Structures
## HttpCode (object)
+ success: 200 - Request processed successfully
+ not_found: 404 - Content requested not found
+ forbidden: 403 - Access to content is forbidden
I would reference it as such:
+ Response (HttpCode.success) (application/json)
...
It obviously does not work and I cannot find anything that pertains to what I want to do in the docs. Maybe i've missed it.
So how do you do it? Is it possible?
Thanks!
This is not possible. Their representative in GitHub closed my issue.
https://github.com/apiaryio/api-blueprint/issues/411
Here's a snippet of my apib document.
Essentially, I want to be able to put additional descriptive information after the Request and Response sections, however this information is not rendered. Instead any further text under a new heading is interpreted as part of the response 200 section. I would like to be able to put a table in the Errors section, so this data would ideally be markdown rendered. Is this possible with aglio?
Thanks!
#### Rate Limiting
This endpoint allows 20 requests per hour.
+ Request (application/json)
+ Attributes (object)
+ id (number)
+ Response 200 (application/json)
+ Attributes (object)
+ status: success (string)
### Errors
Table of error codes
Cameron, this is only currently possible within the description section before the request/response pairs. For example:
## My Resource [/foo]
### My Action [GET]
#### Rate Limiting
This endpoint allows 20 requests per hour.
#### Errors
Table of error codes
+ Request (application/json)
+ Attributes (object)
+ id (number)
+ Response 200 (application/json)
+ Attributes (object)
+ status: success (string)
Alternatively, you could hard code this sort of information in a custom template which would give you full control over what goes where. The reason I say "hard code" is because the API Blueprint parser is seeing your text as belonging to the response rather than the action or example, and I can't modify that behavior within Aglio. You could open a ticket on the upstream API Blueprint repository to request such a feature or use the workaround above.
One last note - you can describe 400 and 500 level responses as request/response pairs. Since the request/response pairs are rendered in the order given in the document you can ensure the error examples show up last.
I'm using HTTP Resource Test on Firefox and want to simulate a POST request. However I didn't find where to write the post parameters. There are only URI, Representation and Headers, is there any way that I can pass with some post parameter? (In Json format?)
The payload of the post should go in the body of the request. It's shown here:
https://addons.cdn.mozilla.net/img/uploads/previews/full/54/54035.png?modified=1297743921
For example, if you were posting a JSON document you could just paste the JSON in the "Body" text area.
The payload of the post should go in 'Client Request' / 'Representation'.
It's shown on this screenshot.
As an aside, this answer describes an excellent test server to use as a sanity-check.