【问题标题】:Creating ticket with attachment in Freshdesk在 Freshdesk 中创建带有附件的工单
【发布时间】:2015-01-22 07:16:20
【问题描述】:

我想在freshdesk api 中创建带有附件的工单。我可以创建没有附件的票证。这是我的示例代码:

post_dict = {
    'helpdesk_ticket': {
        'description': "Testing Code sample 3",
        'subject': "example7",
        'email': "example7@example.com",
        'priority': 2,
        'status': 2,
    },
}

headers = {'Content-Type': 'application/json'}
r = requests.post(FRESHDESK_URL + '/helpdesk/tickets.json',
        auth=(FRESHDESK_API_KEY, "X"),
        headers=headers,
        data=json.dumps(post_dict),
        )

raw_input(r.status_code)
raw_input(r.content)

这仅用于在 Freshdesk 中创建工单。现在使用相同的 post_dict 我想创建带有附件的票证。欢迎任何有关如何使用此 json 请求方法或任何其他方法实现此目的的建议。

【问题讨论】:

    标签: python json openerp python-requests freshdesk


    【解决方案1】:

    创建带有附件的工单需要多部分表单提交。不幸的是,这意味着请求与没有附件的简单请求非常不同。

    每个字段都需要作为单独的表单写入请求,在它之前有一个“边界”,在它之后有一个字符返回。

    然后,每个附件都应该写入请求,同样在附件写入之前有一个边界,之后添加一个字符返回。

    在响应结束时,必须写入最终边界。这与用于边界的字符串相同,但在边界前后还包含 2 个破折号 (--),以表示它是最终的。如果没有最终边界,FreshDesk 会给出 500 内部服务器错误,因为几周前他们的 api 发生了一些变化(它过去常常接受最后的非最终边界)。

    【讨论】:

      【解决方案2】:

      对于发送附件,Content-Type 必须在multipart/form-data。示例 cURL 可能会对您有所帮助。

      curl -v -u yourmail@gmail.com:yourpassword -F 
      "attachments[]=@/path/to/attachment1.ext" -F     
      "attachments[]=@/path/to/attachment2.ext" -F "email=example@example.com" -F     
      "subject=Ticket Title" -F "description=this is a sample ticket" -X POST 
      'https://yoururl.freshdesk.com/api/v2/tickets'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-06
        • 1970-01-01
        相关资源
        最近更新 更多