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 の知識をお持ちの方がいらっしゃいましたら、お役に立てれば幸いです。
ありがとう