我在使用 API Jama 将附件附加到项目时遇到问题。
我需要自动化我的工作并使用 python 创建项目并将 zip 文件附加到它们。 通过控制台,我可以使用 zip 文件创建附件并将其附加到我的项目中。
但是使用 API Jama 我不知道如何创建我的附件..
在文档中似乎我必须使用这个功能:
def put_attachments_file(self, attachment_id, file_path):
"""
Upload a file to a jama attachment
:param attachment_id: the integer ID of the attachment item to which we are uploading the file
:param file_path: the file path of the file to be uploaded
:return: returns the status code of the call
"""
resource_path = 'attachments/' + str(attachment_id) + '/file'
with open(file_path, 'rb') as f:
files = {'file': f}
try:
response = self.__core.put(resource_path, files=files)
except CoreException as err:
py_jama_rest_client_logger.error(err)
raise APIException(str(err))
self.__handle_response_status(response)
return response.status_code
但我不知道如何创建attachment_id然后将我的zip文件关联到它。
感谢您的帮助!
解决方案
# Connect yo your client
client = JamaClient('your_url', credentials=('your_login', 'your_pwd'))
# Post the attachment to your project and get the attachment_id
client.post_project_attachment(your_projectID, 'attachment_name', 'description')
# Load the file to attach
client.put_attachments_file(attachment_id, path_to_your_file)
# Link your attachment to your item
client.post_item_attachment(item_id, attachment_id)
希望有用!