1

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 " }
kybosha
  • 13
  • 3
  • 1
    newlines (i.e. `\n`) are not valid by themselves in JSON and must be escaped; it doesn't seem like your request does that properly? – MatsLindh Dec 14 '22 at 22:20
  • That's what I spotted : in the `doc` field for the error, at line 2 pos 46 there is an unescaped `\n` that is not there in the `--data-raw` you provided with Postman. Try to add this newline in what you send with Postman and you should get the same error. Then try to escape it i.e. send `\\n` instead, and it should work (except there are more `\n` after). – Lenormju Dec 15 '22 at 06:43
  • Nice question and [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) by the way :) – Lenormju Dec 15 '22 at 06:44

0 Answers0