1

I am using the following example and keep getting an response from the server of 100. The image does not update in Square at all.

Found from: Square Connect API - image upload - Empty Reply From Server code 52 error

https://gist.github.com/tdeck/7118c7128a4a2b653d11

(blanked out locationa and item id) POST to https://connect.squareup.com/v1/XXXXXX/items/XXXXXXX/image with status 100

I am using your example exactly Here are the variables I am sending to it: This is coming from a wordpress install.

uploadItemImage( 
'https://connect.squareup.com/v1/XXXXX/items/XXXXX/image', 
'XXXXXXXXXXX', 
'wp-content/uploads/2015/04/imagename.jpg' 
) 

);

Here is the curl output I get with the jpeg added in Item ID and Token are obscured. The image getting uploaded is quite a bit larger then 209bytes. But that is all that is getting sent.

[url] => https://connect.squareup.com/v1/me/items/ITEMID/image
[content_type] => 
[http_code] => 100
[header_size] => 71
[request_size] => 288
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 61.486827
[namelookup_time] => 0.114398
[connect_time] => 0.225888
[pretransfer_time] => 1.347979
[size_upload] => 209
[size_download] => 0
[speed_download] => 0
[speed_upload] => 3
[download_content_length] => -1
[upload_content_length] => 209
[starttransfer_time] => 1.396955
[redirect_time] => 0
[redirect_url] => 
[primary_ip] => 74.122.189.136
[certinfo] => Array
    (
    )

[primary_port] => 443
[local_ip] => 192.168.1.117
[local_port] => 60968
[request_header] => POST /v1/me/items/ITEMID/image HTTP/1.1
Host: connect.squareup.com
Accept: */*
Authorization: Bearer TOKEN
Content-Length: 209
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------754042306466c83e
Community
  • 1
  • 1
Prana
  • 11
  • 2
  • How large is the image you're trying to upload? – Troy Apr 04 '16 at 18:03
  • I have tried all differnet sizes. It is roughly 10kb but up to 60kb 150x150 or 750 x 750px – Prana Apr 05 '16 at 19:36
  • Working node.js snippet for image upload here: https://stackoverflow.com/questions/51289166/square-connect-api-image-upload-node-js/51314822#51314822 – chadhamre Jul 12 '18 at 21:41

1 Answers1

0

It looks like a mime-type check was added to the API since I wrote that example code. In order to add the content type header to the image part of the multipart request, you need to change

curl_setopt($ch, CURLOPT_POSTFIELDS, ['image_data' => "@$image_file"]);

to

curl_setopt($ch, CURLOPT_POSTFIELDS, ['image_data' => "@$image_file;type=image/jpeg"]);

After trying that, it worked for me. I'll update my gist to reflect this.

Troy
  • 1,599
  • 14
  • 28
  • Hi Troy, Thanks for the response, updated the code and still getting the 100 continue issue. I have upated the question with the curl output. – Prana Apr 04 '16 at 15:44
  • I've tried a few different things with this code, and have been unable to reproduce the problem you're having. If you try running the PHP on your local machine, do you have the same issue? Maybe it's some weird bug in an old version of PHP on your host? – Troy Apr 05 '16 at 21:22
  • I have used it on a couple different machines. PHP version of 5.6 or higher. Very strange issue. Could it be how I am linking to the image? Do you need server absolute path to work? I have been using relative. – Prana Apr 08 '16 at 14:07
  • I think your best bet might be to email developers@squareup.com with information about your merchant token, item ID, etc... Then someone might be able to look through the logs and help you. – Troy Apr 08 '16 at 18:29