У меня возникли проблемы с 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)
Я надеюсь, что это может быть полезно!