Add article with attachment in PHP curl

Infos:

  • Used Zammad version: fresh from git
  • Used Zammad installation source: (source, package, …) deb
  • Operating system: ubuntu 18.04
  • Browser + version: safari (current)

Hello everybody,

I’m trying to create an article with an attachment to a ticket using php and curl. My parameter-array is:

Array ( [ticket_id] => 520 [subject] => Serviceanfrage ohne Anlage [body] => Dies ist mein Kommentar. [type] => email [content_type] => text/html [attachments] => Array ( [0] => Array ( [filename] => file.txt [data] => aGVsbG8gd29ybGQ= [mime-type] => text/plain ) ) )

And after “http_build_query” it looks like this:

ticket_id=520&subject=Serviceanfrage+ohne+Anlage&body=Dies+ist+mein+Kommentar.&type=email&content_type=text%2Fhtml&attachments%5B0%5D%5Bfilename%5D=file.txt&attachments%5B0%5D%5Bdata%5D=aGVsbG8gd29ybGQ%3D&attachments%5B0%5D%5Bmime-type%5D=text%2Fplain

For me it looks good, but i get the following error:

{“error”:“undefined method `each_with_index’ for #\u003cActionController::Parameters:0x000055e0551e7018\u003e”}

Any ideas?

Greetings from Germany

Michael

I solved it by myself. For everyone interested in the solution:

The problem was the format with http_build_query. I changed the format to json in this way:

curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-Type: application/json”));
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($params));

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.