0

I am trying to send attachment to a ticket using the API making sure it is sent multipart/form-data however I am not able to do so.The API docs doesn't show an example for syntax it should be sent with so I can't figure it how to do so. How data is sent:

Input::all();
      $json = json_encode(
          array(
                "helpdesk_note" => array(
                "body" => Input::get('reply'),
                "user_id" => $requester_id,
                "private" => true,
                "attachments" => array(
                    Input::get('photo')                
                )
            )
        )
      );

    $this->curlWrap("tickets/".$ticket_id."/conversations/note.json", $json, "POST");
Guido Leenders
  • 4,232
  • 1
  • 23
  • 43
omarsafwany
  • 3,695
  • 8
  • 44
  • 75

1 Answers1

0

You are doing wrong, please note the attachments need to be in a multipart/form-data, and you are trying to pass the body as JSON. Fresh desk don't allow that.

Please read this RFC1867 this and you can do it! Pay attention in section 6. Examples.

You need put your body in this format:

    Content-type: multipart/form-data, boundary=AaB03x

    --AaB03x
    content-disposition: form-data; name="helpdesk_note[body]"

    Your message here.
    --AaB03x
    content-disposition: form-data; name="helpdesk_note[attachments][][resource]"; filename="fileSomeName.jpg"
    Content-Type: image/jpeg

     ... contents of fileSomeName.jpg here ...
    --AaB03x--

You also need to set these headers:

Content-Type: multipart/form-data
Content-Length: 2632

Content-Length need to be the exact size of all body.

Alex
  • 450
  • 4
  • 14