I have the following POST method definded in OpenAPI:
post:
tags:
- Courses
description: Creates a new Course and add it to specified Program
parameters:
- name: Program
in: path
description: Specified Program to add the new course to
required: true
schema:
type: string
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Course'
In insomnia I can define the Course object, I want to add via the body/JSON tab, however how can I define the needed parameter? It doesn't work in the Query tab the same way it does for GET methods.
Do I manually set the path of the POST request with the parameter, or is there a build in way (or is it not possible at all)?
Here is the curl when trying to add the Program Parameter in the Query tab:
curl --request POST \
--url 'http://localhost:8080/Courses?Program=Testprogram' \
--header 'content-type: application/json' \
--data '{
"name": "TestCourse",
"type": "UE",
"etcs": 26,
"courseID": 909090
}'
I had the exact same issue and my problem was an internal redirect (nginx) from HTTP to HTTPs which changed the request type and made it impossible to maintain the body of the requests.
Oddly enough it worked with "Multipart Form".
So please make sure you provide your FULL URI in Insomnia, including the protocol to use for the request.
I found this issue by copying the request from the Insomnia GUI as a cURL command and pasting it into my terminal, which gave me an 301 Permanently moved. ;)
Related
I'm trying to create Organizational branding via Graph API
Unfortunately it doesn't work as documented
curl --fail-with-body --silent --show-error --oauth2-bearer TOKEN -X PUT -H 'Content-Type: application/json' -d #- https://graph.microsoft.com/v1.0/organization/7c9674e7-ad41-482b-af13-fff7ba1c38f6/branding <<< '{
"backgroundColor":"#FFFF33",
"signInPageText":"Welcome",
"usernameHintText":"hint"
}'
{
'error': {
'code': 'Request_BadRequest',
'message': 'Specified HTTP method is not allowed for the request target.',
'innerError': {
'date': '2021-04-21T12:59:57',
'request-id': 'a5ce577c-d0a9-4888-9999-521d7ba452b1',
'client-request-id': 'a5ce577c-d0a9-4888-9999-521d7ba452b1'
}
}
neither PATCH works:
curl --fail-with-body --silent --show-error --oauth2-bearer TOKEN -X PATCH -H 'Content-Type: application/json' -d #- https://graph.microsoft.com/v1.0/organization/7c9674e7-ad41-482b-af13-fff7ba1c38f6/branding <<< '{
"backgroundColor":"#FFFF33",
"signInPageText":"Welcome",
"usernameHintText":"hint"
}'
{
"error": {
"code": "Request_ResourceNotFound",
"message": "Resource '7c9674e7-ad41-482b-af13-fff7ba1c38f6' does not exist or one of its queried reference-property objects are not present.",
"innerError": {
"date": "2021-04-21T13:07:43",
"request-id": "c2c7056b-0043-40cb-82b8-6d262f190005",
"client-request-id": "c2c7056b-0043-40cb-82b8-6d262f190005"
}
}
I tried opening an Azure support request but they told me
The AAD Developer queue is experiencing a very high number of requests.
Please expect a delay in the assignation as the cases are assigned considering case severity, time in queue, customer service level and business impact.
Since Azure support has proven to be useless yet again, maybe somebody here would be able to help me? :)
Based on my test, I have the same error when I use PUT method.
But PATCH works fine for me.
id should be the organization id or tenant id.
Please get the id first with
GET https://graph.microsoft.com/beta/organization/
Then use the id for PATCH method:
PATCH https://graph.microsoft.com/v1.0/organization/{id}/branding
Content-Type: application/json
Content-Language: en-US
{
"backgroundColor": "#FFFF33",
"signInPageText": "Welcome",
"usernameHintText": "hint"
}
Update:
Application token is not supported for this endpoint. See Permissions.
Microsoft support finally responded (after 2 months!) with
Application Permission are currently not supported on this
endpoint, meaning that you will need an on-behalf of user token with
Delegated permissions to use this endpoint.
Since your goal was to automate this process, one workaround that
sometimes is feasible is to have a dedicated user in your tenant to
perform those actions, and that will authenticate with ROPC flow. This
flow allows to directly send the credentials information (username and
password) and because of that does not require an UI or interaction.
There is currently a known issue regarding the GET and PATCH method for the branding endpoint that is already reported and the fix
is in progress. This issue will cause an 404 error mentioning that the
tenant resource is not found.
Issue seems to be with locale being used, If you wish to get/update
the default branding, can you please try to include an header with
Accept-language as 0 (shown in the below image), if you want to get
branding for any other locale, you’ll need to pass the valid ISO-639
locale.
I have yaml file:
openapi: 3.0.1
info:
title: My API
version: v1
paths:
# /users;id=3;id=4?metadata=true
/users:
get:
parameters:
- in: query
name: offset
schema:
type: integer
description: The number of items to skip before starting to collect the result set
- in: query
name: limit
schema:
type: integer
description: The numbers of items to return
- in: query
name: origin
style: form
explode: false
schema:
type: object
properties:
city:
type: string
zip:
type: string
responses:
'200':
description: A list of users
When I click "execute" in https://editor.swagger.io, the generated Curl looks like this:
curl -X GET "https://editor.swagger.io/users?offset=2&limit=12&origin=city,atlanta,zip,303" -H "accept: */*"
However, I need it to be like this:
curl -X GET "https://editor.swagger.io/users?offset=2&limit=12&origin=city:atlanta|zip:303" -H "accept: */*"
Is it possible to do this? I could not find any info in documentation about setting custom delimeters.
Short answer: No.
Your specific use case isn't covered by serialize parameters and they follow the rfc6570 - it's a good idea to follow the standard if you want to design a well accepted web api.
You specified explode: false and style:form.
When you turn explode:true on you will get this instead:
city=atlanta&zip=303
When you specify style:deepObject you will get:
origin[city]=atlanta&origin[zip]=303
The spaceDelimited and pipeDelimited style won't work with objects.
Working without schema
You can of cause work without a schema and define your origin query parameter of type string.
The documentation should explain exactly what you expect and a little example will help people to use your API.
I won't use that pattern for an open API, but this can be a workaround for an internal API.
We are using PRTG to monitor a number of internal resources, and we have set it up to alert us on a Slack channel and/or via PagerDuty (depending on severity) using their respective APIs. Considering that Slack and PagerDuty are external to us, we would also like to monitor whether our PRTG instance can access them -- basically, a form of self-monitoring or Who Watches the Watchmen?
So far the only reliable method we've found for Slack is to post an actual message to a private "testing" Slack channel, e.g. (Slack URL details redacted):
POST https://hooks.slack.com/services/XXX/YYY/ZZZ
Content-Type: application/json
{ "text": " ", "channel": "#prtg-webhook-test" }
Similarly, PagerDuty's Events API appears to be POST only, and the valid actions are limited to trigger, acknowledge, and resolve:
POST https://events.pagerduty.com/v2/enqueue
Content-Type: application/json
Is there a good way to test HTTPS connectivity without posting an actual Slack message / creating an actual PagerDuty alert? I couldn't find anything in documentation for either service, or a creative way to create an appropriate sensor in PRTG.
For Slack you might rather want to make an call to the API, not to a webhook.
I would recommend using auth.test, since its one of the few methods that has no rate limit.
Also, for the whole Slack service you can see the current status on this official webpage.
For pure connectivity, you can do a POST against the Events API with an empty payload, and you'll get an error message back:
curl --location --request POST 'https://events.pd-staging.com/v2/enqueue' \
--header 'Content-Type: application/json' \
--data-raw '{}'
{
"status": "invalid event",
"message": "Event object is invalid",
"errors": [
"'event_action' is missing or blank",
"'routing_key' must be provided in the body, or provided in the headers using 'x-routing-key'"
]
}
If you'd also like to validate your routing key, you can send an acknowledge event with a dummy dedup_key:
curl --location --request POST 'https://events.pd-staging.com/v2/enqueue' \
--header 'Content-Type: application/json' \
--header 'Cookie: uid=rBGA1lymclmSzRCsAwO3Ag==' \
--data-raw '{
"routing_key": "<your_routing_key>",
"event_action": "acknowledge",
"dedup_key": "something_that_will_never_match_an_open_incident"
}'
{
"status": "success",
"message": "Event processed",
"dedup_key": "something_that_will_never_match_an_open_incident"
}
Note that this will not show up anywhere in the PagerDuty UI, but that could be what you'd want anyways.
I am setting up our api documentation and i'm using swagger-spec and swagger ui.
I got everything working except that my CURL example adds our access_token twice
curl -X DELETE --header "Accept: application/json" "http://api host/api/user?filter%5Bid%5D%5BEQUAL%5D=1&access_token=Token_TOKANE&access_token=Token_TOKANE"
I renamed the api_key in swagger_ui index
var apiKeyAuth = new SwaggerClient.ApiKeyAuthorization("access_token", key, "query");
window.swaggerUi.api.clientAuthorizations.add("access_token", apiKeyAuth);
Screenshot
Swagger delete path
delete:
tags:
- User
summary: Delete user from you organization
operationId: deleteUser
description: Deletes a single by id. Gets id from filter param in query
parameters:
- name: filter[id][EQUAL]
in: query
type: integer
required: true
description: id to delete
responses:
200:
description: OK
schema:
$ref: '#/definitions/Message'
security:
- access_token: []
Security definition
securityDefinitions:
access_token:
type: string
in: query
name: access_token
The same issue can be seen in the swagger-ui live demo
If anyone knows of a fix or workaround i would appreciate it.
This has just been addressed in swagger-js. You can update your swagger-ui by building this locally and using npm link against the local build of swagger-ui. The release of swagger-ui with this fix is coming soon.
I am building an iOS app and it needs to post to a RoR API.
To test the POST, I am running this command:
curl -d #/tmp/data localhost:3000/api/ratings
Where /tmp/data contains an array of hashes:
[ { "uid": "gilt_162929239", "rate": 1 } ]
In Ruby, params looks like this:
[1] pry(#<Api::PromotionRatingsController>)> params
=> {" { \"uid\": \"good_162929239\", \"rate\": 1 } "=>nil,
"format"=>"json",
"action"=>"create",
"controller"=>"api/ratings"}
How do I get Rails to create the array of hashes for me to iterate over with each?
Edit: I see I was missing headers.
Adding to the curl command line:
--header "Accept: application/json" --header "Content-type: application/json"
Now, here are my params:
[1] pry(#<Api::PromotionRatingsController>)> params
=> {"_json"=>[{"uid"=>"good_162929239", "rate"=>1}],
"format"=>"json",
"action"=>"create",
"controller"=>"api/ratings",
"promotion_rating"=>{"_json"=>[{"uid"=>"good_162929239", "rate"=>1}]}}
Still not right.
According to this:
if you’ve turned on config.wrap_parameters in your initializer or
calling wrap_parameters in your controller, you can safely omit the
root element in the JSON/XML parameter. The parameters will be cloned
and wrapped in the key according to your controller’s name by default.
So, my guess is that you either need to include a root element, or set config.wrap_parameters.