OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Cannot resolve errors with Jira API v2

  • Thread starter Thread starter TonyShark007
  • Start date Start date
T

TonyShark007

Guest
my frameworks:

  • python backend fastapi
  • javascript frontend next.js

using this fetch:

Code:
const response = await fetch("UrlToPythonBackend", {
            method: "POST",
            mode: "no-cors", // changing this option in my tries
            headers: {
                "Content-Type": "application/json",
                "X-Atlassian-Token": "no-check",
                "Target": "https://DomainWichWorks100%Fine.atlassian.net/rest/api/2/issue",
                Authorization: 'Basic MyTokenWichWorks100%FineTrustMe',
            },
            body: JSON.stringify({
                test: "Test"
            }),
            redirect: 'follow'
        })

using this backend:

Code:
from fastapi import FastAPI
from fastapi import Body, Header, Request, HTTPException
from typing import Annotated
import requests
import json
from fastapi_cors import CORS
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel

app = FastAPI()

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],  # or specify methods like ["GET", "POST"]
    allow_headers=["*"],  # or specify headers like ["Content-Type", "Authorization"]
)


@app.post("/proxy")
async def proxyPost(request: Request, body = Body(), target: str = Header(alias="Target")):
    """
    Proxies the POST request to the specified target URL.

    Args:
        request (Request): The incoming request object.
        body (dict): The request body as a dictionary.
        target (str): The target URL to proxy the request to.

    Returns:
        dict: The JSON response from the target URL.
    """
    print(f"Request Body: {body}")


    headers = {key: value for key, value in request.headers.items() if key.lower() != 'host'}


    load = str(body)
    load = load.replace("'", "\"")

    response = requests.post(target, json=load, headers=headers)
    try:
        response_json = response.json()
    except:
        response_json = response.text
    return response_json

    #response = requests.post(target, json=body, headers=headers)
    #response_json = response.json()

Short: getting the 422 Unprocessable Entity HTTPError

Detailed: I've tried to deploy the backend on a server but then i'm getting with cors the XSRF check error and with no-cors the Unprocessable Entity Error

Using the Backend Localhost (changed the mode of the fetch to cors), everything works fine except the jira api. On localhost i'm getting XSRF check failed even though im using the solution Jira provided: X-Atlassian-Token: no-check

<p>my frameworks:</p>
<ul>
<li>python backend fastapi</li>
<li>javascript frontend next.js</li>
</ul>
<p>using this fetch:</p>
<pre><code>const response = await fetch("UrlToPythonBackend", {
method: "POST",
mode: "no-cors", // changing this option in my tries
headers: {
"Content-Type": "application/json",
"X-Atlassian-Token": "no-check",
"Target": "https://DomainWichWorks100%Fine.atlassian.net/rest/api/2/issue",
Authorization: 'Basic MyTokenWichWorks100%FineTrustMe',
},
body: JSON.stringify({
test: "Test"
}),
redirect: 'follow'
})
</code></pre>
<p>using this backend:</p>
<pre><code>from fastapi import FastAPI
from fastapi import Body, Header, Request, HTTPException
from typing import Annotated
import requests
import json
from fastapi_cors import CORS
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel

app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"], # or specify methods like ["GET", "POST"]
allow_headers=["*"], # or specify headers like ["Content-Type", "Authorization"]
)


@app.post("/proxy")
async def proxyPost(request: Request, body = Body(), target: str = Header(alias="Target")):
"""
Proxies the POST request to the specified target URL.

Args:
request (Request): The incoming request object.
body (dict): The request body as a dictionary.
target (str): The target URL to proxy the request to.

Returns:
dict: The JSON response from the target URL.
"""
print(f"Request Body: {body}")


headers = {key: value for key, value in request.headers.items() if key.lower() != 'host'}


load = str(body)
load = load.replace("'", "\"")

response = requests.post(target, json=load, headers=headers)
try:
response_json = response.json()
except:
response_json = response.text
return response_json

#response = requests.post(target, json=body, headers=headers)
#response_json = response.json()

</code></pre>
<p>Short: getting the 422 Unprocessable Entity HTTPError</p>
<p>Detailed:
I've tried to deploy the backend on a server but then i'm getting with cors the XSRF check error and with no-cors the Unprocessable Entity Error</p>
<p>Using the Backend Localhost (changed the mode of the fetch to cors), everything works fine except the jira api. On localhost i'm getting XSRF check failed even though im using the solution Jira provided: X-Atlassian-Token: no-check</p>
 

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top