使用 API 调用在 Jira Service Management 中创建项目 - 错误数据 <Response 400>

Create Project within Jira Service Management with API Call - wrong data <Response 400>

在终端 (mac) 外的 rest-api curl 正常工作:

curl -X POST \       
https://atc-{url}.net/sd/rest/api/2/project \
-H 'Authorization: Basic *******************' \ 
-H 'Content-Type: application/json' \
-H 'cache-control: no-cache' \
-d '{
"key": "TEST",
"name": "TEST Project",
"projectTypeKey": "service_desk",
"projectTemplateKey": "com.atlassian.servicedesk:basic-service-desk-project",
"description": "Example Project description",
"lead": "Username",
"assigneeType": "PROJECT_LEAD",
"avatarId": 10200
}'

正在我的 Jira 实例中创建一个项目。另一方面,在我的 Python 脚本中,我使用的是 requests 库。我一直收到 400 错误响应,但我尝试了各种 headers 和数据输入,但它总是 returns 400.... 代码如下所示:

headers = {
    'Cache-Control': 'no-cache',
    'Content-Type': 'application/json',
    'Authorization': 'Basic ********************'
}

data = {'key': 'TEST',
        'name': 'test_project',
        'projectTypeKey': 'service_desk',
        'projectTemplateKey': 'com.atlassian.servicedesk:basic-service-desk-project',
        'description': 'description',
        'lead': 'NAME',
        'assigneeType': 'PROJECT_LEAD',
        'avatarId': 10200
        }

try:
    log.info("try to start curl for {} creation".format(project_key,))
    res = requests.post(
        'https://atc-{url}/sd/rest/api/2/project', headers=headers, data=data)
    log.info(res)
    project_created = True

    if res.status_code == 500:
        project_created = False

except:
    project_created = False
    log.info("curl failed")

我认为我的数据部分已损坏...

已将 data=data 更改为 json=data,现在可以使用了。