How to – Post a JSON body in Swagger

Recently working with an Azure Functions , we had to define its REST Signature using Swagger to be able to use it within PowerApps.

The Azure Function expected the code query parameter basically the apiKey for the function and JSON Body with custom object named Lead having following properties as POST method.

  • topic
  • fullname
  • email

This is how we’d define our Lead Object and pass it as one of the parameters in the body.


swagger: '2.0'
info:
title: mycrmfunctionapp.azurewebsites.net
version: 1.0.0
host: mycrmfunctionapp.azurewebsites.net
basePath: /
schemes:
- https
- http
paths:
/api/MyLeadWebHook:
post:
operationId: /api/MyLeadWebHook/post
produces:
- application/json
consumes:
- application/json
parameters:
- name: Lead
in: body
description: lead object
required: true
schema:
$ref: '#/definitions/Lead'
description: >-
Replace with Operation Object
#http://swagger.io/specification/#operationObject
responses:
'200':
description: Success operation
security:
- apikeyQuery: []
definitions:
Lead:
description: Lead Object
properties:
fullname:
type: string
description: full name
topic:
type: string
description: topic
email:
type: string
description: topic
required:
- fullname
- topic
- email
securityDefinitions:
apikeyQuery:
type: apiKey
name: code
in: query

We can use the Swagger Editor built-in with Azure Functions or http://editor.swagger.io/#/ to edit and test our Swagger.

Hope it helps..

Advertisements