I'm building out an automated process, one part involves firing a webhook using Jira Automation when a Jira Service Management ticket is created. On creation a Jira automation rule is in place to send a webhook to a fastapi webservice I have created. I'm new to fastapi (have used flask previously) so I think I may be getting something wrong with Response Models.
The issue I'm having is the fastapi service returns 422 Unprocessable Entity when receiving the payload from Jira. I narrowed it down to be the description field and built out a super stripped down fastapi webservice to debug this further, running it with uvicorn main:app --reload
. Here's the full code:
from fastapi import FastAPI, Request
from pydantic import BaseModel
app = FastAPI()
class Data(BaseModel):
description: str
@app.post("/desc")
def read_desc(data: Data):
webhook = data
print(webhook)
return {"Data": webhook}
The details of the request that comes from Jira are as follows:
Request
POST https://random-ngrok-url/desc
Headers
Accept: */*
Content-Type: application/json
Payload
{ "description" : "Application review requested |Project link|https://develop.test.com/app/dashboard/| |User name|MTest| |User e-mail|test@test.com| |SDK version|SDK_V2| 1234 " }
Response
422 Unprocessable Entity
Content-Length: 417
Content-Type: application/json
Date: Wed, 14 Dec 2022 13:09:55 GMT
Ngrok-Trace-Id: random-ngrok-trace-id
Server: uvicorn
Payload
{
"detail": [
{
"loc": [
"body",
47
],
"msg": "Invalid control character at: line 2 column 46 (char 47)",
"type": "value_error.jsondecode",
"ctx": {
"msg": "Invalid control character at",
"doc": "{\n\"description\" : \"Application review requested\n|Project link|https://develop.test.com/app/dashboard/|\n|User name|MTest|\n|User e-mail|test@test.com|\n|SDK version|SDK_V2|\n\n1234\n\"\n}",
"pos": 47,
"lineno": 2,
"colno": 46
}
}
]
}
I feel like there's some encoding or editing being made to the request from Jira, but I can't figure out what. Position 47 just appears to be a standard character?
Note: it works with other fields in the Jira tickets, with the payload being like this:
{
"summary": "Review Application Test"
}
Other things to note
If I perform this exact request from postman the fastapi service responds as expected with 200 returning the description.
Here's the curl output from postman of such a successful request.
curl --location --request POST 'https://random-ngrok-url/desc' \
--header 'Content-Type: application/json' \
--data-raw '{ "description" : "Application review requested |Project link|https://develop.test.com/app/dashboard/| |User name|MTest| |User e-mail|test@test.com| |SDK version|SDK_V2| 1234 " }'
I also did a test by sending the request from Jira to a request inspector and saw the following request details:
POST /inspect/from-jira HTTP/1.1
requestinspector.com
User-Agent: Automation for Jira AC app/1.0
Accept-Encoding: gzip
Accept: */*
Content-Type: application/json
Content-Length: 190
With the payload body being:
{
"description" : "Application review requested
|Project link|https://develop.test.com/app/dashboard/|
|User name|MTest|
|User e-mail|mtest@test.com|
|SDK version|SDK_V2|
1234
"
}
From Postman it's
POST /inspect/from-postman HTTP/1.1
requestinspector.com
User-Agent: PostmanRuntime/7.29.2
Content-Type: application/json
Content-Length: 189
Accept: */*
Accept-Encoding: gzip
Postman-Token: random-postman-token
payload body:
{ "description" : "Application review requested |Project link|https://develop.test.com/app/dashboard/| |User name|MTest| |User e-mail|test@test.com| |SDK version|SDK_V2| 1234 " }