I am trying open ticket with attachment
using : https://github.com/joeirimpan/zammad_py
the zammad server is only testing purpose, there isn’t sensitive data.
from zammad_py.api import *
import base64
t= ZammadAPI(username = "test@test.test",password = "1234",host="x.189.16.230")
dosya = open("/Users/macbook/zammad_py-develop/zammad_py/d.txt","rb").read()
artic = {
"ticket_id":54,
"to":"",
"cc":"",
"subject":"some subject",
"body":"huhuhuu<br>huhuhuu<br>huhuhuu<br><br>",
"content_type":"text/html",
"type":"web",
"internal":False,
"time_unit":"12",
"attachments":[
{
"filename": "d.txt",
"data": base64.b64encode(dosya) ,
"mime-type": "text/plain"
}
]
}
print(t.ticket_article.create(artic))
I am getting error
TypeError: Object of type bytes is not JSON serializable
Also I am tried to modify api source code to:
t.ticket_article.create_with_image_upload(artic,dosya)
def create_with_image_upload(self, params, files):
"""Create the requested resource
:param params: Resource data for creating
"""
response = self._connection.session.post(
self.url + '?expand=true',
json=params,
files={'file': files} #<=========added for post in requests(url, files, json)
)
return self._raise_or_return_json(response)
artic = {
"ticket_id":54,
"to":"",
"cc":"",
"subject":"some subject",
"body":"huhuhuu<br>huhuhuu<br>huhuhuu<br><br>",
"content_type":"text/html",
"type":"web",
"internal":False,
"time_unit":"12",
"attachments":[
{
"filename": "d.txt",
"data": "text/plain;" ,
"mime-type": "text/plain"
}
]
}
t.ticket_article.create_with_image_upload(artic,dosya)
RESPONSE 404: b’{“error”:“Couldn’t find Ticket with ‘id’=”}’
also no luck,
also tried
dosya = open("/Users/macbook/zammad_py-develop/zammad_py/d.txt","rb").read()
artic = {
"ticket_id":54,
"to":"",
"cc":"",
"subject":"some subject",
"body":"huhuhuu<br>huhuhuu<br>huhuhuu<br><br>",
"content_type":"text/html",
"type":"web",
"internal":False,
"time_unit":"12",
"attachments":[
{
"filename": "d.txt",
"data": json.dumps(dosya.decode("utf-8")),
"mime-type": "text/plain"
}
]
}
print(t.ticket_article.create_with_image_upload(artic,dosya))
RESPONSE : b’{“error”:“Couldn’t find Ticket with ‘id’=”}’
without attachment I can create articles for ticket with:
artic = {
"ticket_id":54,
"to":"",
"cc":"",
"subject":"some subject",
"body":"huhuhuu<br>huhuhuu<br>huhuhuu<br><br>",
"content_type":"text/html",
"type":"web",
"internal":False,
"time_unit":"12",
}
t.ticket_article.create(artic)
Success
{
"id":161,
"ticket_id":54,
"type_id":11,
"sender_id":2,
"from":"test test <test@test.test>",
"to":"",
"cc":"",
"subject":"some subject",
"reply_to":"None",
"message_id":"None",
"message_id_md5":"None",
"in_reply_to":"None",
"content_type":"text\/html",
"references":"None",
"body":"huhuhuu<br>huhuhuu<br>huhuhuu<br><br>",
"internal":false,
"preferences":{
},
"updated_by_id":30,
"created_by_id":30,
"origin_by_id":30,
"created_at":"2018-11-21T08:40:58.108Z",
"updated_at":"2018-11-21T08:40:58.108Z",
"attachments":[
],
"type":"web",
"sender":"Customer",
"created_by":"auto-1542404189-832322",
"updated_by":"auto-1542404189-832322",
"origin_by":"auto-1542404189-832322"
}
any assistance will be appreciated