Attach images to new Zoho Desk ticket

Attach images to new Zoho Desk ticket

Hi all,
I am trying to attach images to a ticket.  I am using PHP and the Desk API and am able to create the ticket fine.  When I try to attach an image using the below code, there is nothing in the response..  it is just empty and nothing is attached to the ticket.  I have confirmed the image file URLs are accessible. Is there a better way I should do this on ticket creation (as the images are ready when the ticket is created)?  What is wrong with my code?
  1. public function attachFiles($ticketid, $images)


            $access_token = $this->get_access_token();

            if(isset($images) && !empty($images)){

                foreach($images as $key => $image) {

                    $ch_image = curl_init();

                    curl_setopt( $ch_image, CURLOPT_URL, ''.$ticketid.'/attachments?isPublic=true' );

                    curl_setopt( $ch_image, CURLOPT_POST, true );

                    $post_fields = array(

                        'file' => new CURLFile($image)


                    curl_setopt($ch_image, CURLOPT_POSTFIELDS, $post_fields);

                    curl_setopt($ch_image, CURLOPT_RETURNTRANSFER, true);

                    curl_setopt( $ch_image, CURLOPT_HTTPHEADER, array(

                        'Authorization: Zoho-oauthtoken ' . $access_token,

                        'orgId: ******',


                    ) );


                    $img_response = curl_exec( $ch_image );


                    $image_upload_response = json_decode($img_response, true);

                    print_r($image_upload_response);  //this is empty!?



                            Zoho Desk Resources

                            • Desk Community Learning Series

                            • Digest

                            • Functions

                            • Meetups

                            • Kbase

                            • Resources

                            • Glossary

                            • Desk Marketplace

                            • MVP Corner

                            • Word of the Day

                                Zoho Marketing Automation

                                        Manage your brands on social media

                                                Zoho TeamInbox Resources

                                                  Zoho DataPrep Resources

                                                    Zoho CRM Plus Resources

                                                      Zoho Books Resources

                                                        Zoho Subscriptions Resources

                                                          Zoho Projects Resources

                                                            Zoho Sprints Resources

                                                              Qntrl Resources

                                                                Zoho Creator Resources

                                                                  Zoho WorkDrive Resources

                                                                    Zoho Campaigns Resources

                                                                      Zoho CRM Resources

                                                                      • CRM Community Learning Series

                                                                        CRM Community Learning Series

                                                                      • Tips


                                                                      • Functions


                                                                      • Meetups


                                                                      • Kbase


                                                                      • Resources


                                                                      • Digest


                                                                      • CRM Marketplace

                                                                        CRM Marketplace

                                                                      • MVP Corner

                                                                        MVP Corner



                                                                          Design. Discuss. Deliver.

                                                                          Create visually engaging stories with Zoho Show.

                                                                          Get Started Now