Search code examples
postswaggerinsomnia

How to send a POST request with parameters in Insomnia?


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
}'

Solution

  • 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. ;)