1

Pivotal Tracker API を使用して、python を使用してストーリーを投稿しようとしています。Python requests モジュールを使用してこれを行うことができます。以下は、新しいストーリーを作成するために使用できるサンプル コードです。

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'}

偉大な。ここで、ストーリーを作成してラベルを追加したいと思います。https://www.pivotaltracker.com/help/api/rest/v5の 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 の知識をお持ちの方がいらっしゃいましたら、お役に立てれば幸いです。

ありがとう

4

1 に答える 1

2

解決しました。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)) します。JSON を送信し、JSON を受け入れることを API に伝える必要があります。

于 2015-03-30T17:02:24.427 に答える