Error in upload image of product using api
HTTP/1.1 100 Continue HTTP/1.1 405 Method Not Allowed Date: Mon, 16 Aug 2021 09:59:02 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive x-ls-api-bucket-level: 10/60 x-ls-acct-id: 218427 x-ls-shard-id: 19 x-ls-oauth-client-id: 72626 x-ls-api-drip-rate: 1 allow: POST, GET, PUT, DELETE x-ls-master-system: false x-ls-master-account: true x-ls-master-catalog: false vary: Accept-Encoding x-frame-options: SAMEORIGIN x-xss-protection: 1; mode=block x-content-type-options: nosniff x-ls-platform: miku x-ls-via: ra CF-Cache-Status: DYNAMIC Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" Server: cloudflare CF-RAY: 67f9cebb59760e80-BOM {"httpCode":"405","httpMessage":"Method Not Allowed","message":"PUT, POST require an input body.","errorClass":"Exception"}
--PHP CODE---
<?php
$url = "https://api.lightspeedapp.com/API/Account/xxxxx/Item/3086/Image.json";
$headers = array(
'Authorization: Bearer '.$bearer_token,
'Accept: application/json',
'Content-Type: multipart/form-data');
$imagefile = 's.jpg'; //Full path of image file you wish to use
$postfields = array(
'image' => new CURLFile($imagefile, 'text/plain', 's.jpg'));
$filesize = filesize($imagefile);
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_POST => 1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_HTTPHEADER => $headers,
CURLOPT_VERBOSE => 1,
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_INFILESIZE => $filesize,
CURLOPT_RETURNTRANSFER => true
); // cURL options
curl_setopt_array($ch, $options);
$output = curl_exec($ch);
curl_close($ch);
echo '<pre>';
print_r($output);
echo '</pre>';
?>
9 comments
Hi @jbs_123,
Thank you for contacting us.
Sorry for delay in answering your question. What I see is that you don't send the data field in your $postfield variable. I just did a test with my code and it worked for me. Here's my code:
I hope this helps.
Hello team.
I have tried same code which you have given in last post but still i getting error please check attachment image.
upload image size is 147kb.
----------------------------------
$url = "https://api.lightspeedapp.com/API/Account/xxxxx/Image.json";
$headers = array(
'Authorization: Bearer 250119e9eb09447541b181507d86c0184f35bd5c',
'Accept: application/json',
'Content-Type: multipart/form-data');
$imagefile = 's.jpeg'; //Full path of image file you wish to use
$postfields = array(
'data' => '{"description": "Test Image","ordering": 1,"itemID": 3587}',
'image' => new CURLFile($imagefile, 'text/plain', 'image.jpeg'));
$filesize = filesize($imagefile);
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_VERBOSE => 1,
CURLOPT_POSTFIELDS => json_encode($postfields),
CURLOPT_INFILESIZE => $filesize,
CURLOPT_RETURNTRANSFER => true
); // cURL options
curl_setopt_array($ch, $options);
$output = curl_exec($ch);
curl_close($ch);
echo '<pre>';
print_r($output);
echo '</pre>';
------------------------------------------
The error details indicate the image file size is too large. Apparently 8 megabytes or more is rejected. Try scaling down a smaller image and retry.
Hello, gregarican
Thank you for supporting.
Which size (byte,kb,mb) of image, api will accept?
I trying using kb but api giving same response.
Thank you.
@jbs_123,
The image names are not the same.
Hello team,
I have created same code which you given in post but still server giving same image size's error.
Please let me know what is wrong in below code.
Thank you.
---------------------------
$url = "https://api.lightspeedapp.com/API/Account/xxxxx/Image.json";
$headers = array(
'Authorization: Bearer 72ce4834a854626097e8509e94b5aaf6994ca2b3',
'Accept: application/json',
'Content-Type: multipart/form-data');
$imagefile = 'ss.jpeg'; //Full path of image file you wish to use
$postfields = array(
'data' => '{"description": "Test Image","ordering": 1,"itemID": 3587}',
'image' => new CURLFile($imagefile, 'text/plain', 'ss.jpeg'));
$filesize = filesize($imagefile);
$ch = curl_init();
$options = array(
CURLOPT_URL => $url,
CURLOPT_HEADER => true,
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_VERBOSE => 1,
CURLOPT_POSTFIELDS => $postfields,
CURLOPT_INFILESIZE => $filesize,
CURLOPT_RETURNTRANSFER => true
); // cURL options
curl_setopt_array($ch, $options);
$output = curl_exec($ch);
curl_close($ch);
echo '<pre>';
print_r($output);
echo '</pre>';
--------------------------------------------------------------------------------
Response is :
Hello team
final i got solution it is described in image.
Api is not accepting image without root path.
So DIR function is help to get root path and now it's working.
Thank you for all help.
Hi @jbs_123,
Okay perfect!
Hello team,
My concern is, how to apply filter(ascending,disanding) on 'Default' price of Inventory item using apis?
Thank you.