我试图使用关键的跟踪器API发布一个使用python的故事。我可以使用python请求模块这样做。下面是我可以用来创建一个新故事的示例代码:
payload = {"name":"Create story w/create label"}
requests.post('https://www.pivotaltracker.com/services/v5/projects/xxxxxx/stories', data=payload4, headers={'X-TrackerToken':token}).json()输出为
{u'created_at': u'2015-03-04T18:47:28Z',
u'current_state': u'unscheduled',
u'id': xxxxxx,
u'kind': u'story',
u'labels': [],
u'name': u'Create story w/create label',
u'owner_ids': [],
u'project_id': xxxxxx,
u'requested_by_id': xxxxxx,
u'story_type': u'feature',
u'updated_at': u'2015-03-04T18:47:28Z',
u'url': u'https://www.pivotaltracker.com/story/show/xxxxxx'}太棒了。现在,我想创建一个故事,并在其中添加一个标签。根据POST /projects/{project_id}/stories API,我应该能够将json格式化如下,并运行POST请求:
payload = {"name":"Create story w/create label","labels":[{"name":"orbit"}]}
requests.post('https://www.pivotaltracker.com/services/v5/projects/xxxxxx/stories', data=payload, headers={'X-TrackerToken':token}).json()然而,我得到了以下400条回复:
{u'code': u'invalid_parameter',
u'error': u'One or more request parameters was missing or invalid.',
u'general_problem': u"'labels' must be an array of label values",
u'kind': u'error'}据我所知,我格式化有效负载json的方式是正确的,标签资源json被正确地格式化。我不确定这个错误是在我头上,还是在别的什么地方。如果有API知识的人能提供一些帮助,我们将不胜感激。
谢谢
发布于 2015-03-30 17:02:24
解决了,存在一个JSON编码问题。我们从未告诉过枢轴跟踪器我们要发送JSON。这个代码片段很有效:data = { "labels": ["major request"], "name": "some cool feature", "description": "solve world hunger", "comments": ["requested by not the 1%"] } headers = {'X-TrackerToken': TRACKER_TOKEN, 'Content-type': 'application/json', 'Accept': 'application/json' } return requests.post(url, headers=headers, data=json.dumps(data))需要告诉API我们正在发送JSON并接受JSON。
https://stackoverflow.com/questions/28872182
复制相似问题