Jump to content

Edit History

Sterk

Sterk

Bonjour à tous

Je découvre les webservice avec Prestashop et j'ai un souci, j'obtient toujours un code 302 lorsque que je tente de mettre à jour une image d'un produit

int(302) string(276) "HTTP/1.1 100 Continue HTTP/1.1 302 Found Date: Sat, 17 Aug 2019 13:40:13 GMT Server: Apache X-Powered-By: PHP/7.0 Location: http://myshop.xyz/shop/index.php?url=images%2Fproducts%2F104954%2F Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 "

J'ai bien généré ma clé api dans l'interface admin

Voici mon code :

 

 $url = 'https://www.myshop/shop';
   $key  = 'XYZXYZXYZXYZXYZXYZXYZXYZ';

    $psProductId = 104954;
    $urlImage = $url.'/api/images/products/'.$psProductId.'/';
   
 
    $image_path = '/home/web/www/shop/img/p/2/6/0/1/2601-large_default.jpg';
    $image_mime = 'image/jpg'; 

   $args['image'] = new CurlFile($image_path, $image_mime);

    
     
   
    $ch = curl_init();
    
   //  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data','Expect:'));
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
    curl_setopt($ch, CURLOPT_URL, $urlImage);
    curl_setopt($ch, CURLOPT_POST, 1);
    
    curl_setopt($ch, CURLOPT_USERPWD, $key.':');
  //curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
  //curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));  //test 2
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('image'=>"@".$image_path.";type=image/jpeg")); //test 3
    $result = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    //echo curl_error($ch);
   
    var_dump($httpCode);
     var_dump($result);
    
      curl_close($ch);

	if (200 == $httpCode) {
        echo 'Product image was successfully created.';
    }

Je possède Prestashop 1.7.6 et suis hébergé chez OVH  avec du php 5.6

Merci pour tout conseil

 

 

 

 

Sterk

Sterk

Bonjour à tous

Je découvre les webservice avec Prestashop et j'ai un souci, j'obtient toujours un code 302 lorsque que je tente de mettre à jour une image d'un produit

int(302) string(276) "HTTP/1.1 100 Continue HTTP/1.1 302 Found Date: Sat, 17 Aug 2019 13:40:13 GMT Server: Apache X-Powered-By: PHP/7.0 Location: http://myshop.xyz/shop/index.php?url=images%2Fproducts%2F104954%2F Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 "

J'ai bien généré ma clé api dans l'interface admin

Voici mon code :

 

 $url = 'https://www.myshop/shop';
   $key  = 'XYZXYZXYZXYZXYZXYZXYZXYZ';

    $psProductId = 104954;
    $urlImage = $url.'/api/images/products/'.$psProductId.'/';
   
 
    $image_path = '/home/web/www/shop/img/p/2/6/0/1/2601-large_default.jpg';
    $image_mime = 'image/jpg'; 

   $args['image'] = new CurlFile($image_path, $image_mime);

    
     
   
    $ch = curl_init();
    
   //  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data','Expect:'));
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
    curl_setopt($ch, CURLOPT_URL, $urlImage);
    curl_setopt($ch, CURLOPT_POST, 1);
    
    curl_setopt($ch, CURLOPT_USERPWD, $key.':');
  //curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
  //curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));  //test 2
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('image'=>"@".$image_path.";type=image/jpeg")); //test 3
    $result = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    //echo curl_error($ch);
   
    var_dump($httpCode);
     var_dump($result);
    
      curl_close($ch);

	if (200 == $httpCode) {
        echo 'Product image was successfully created.';
    }

Je possède Prestashop 1.7.6 et suis hébergé chez OVH  avec du php 5.6

Merci pour tout conseil

 

 

 

 

Sterk

Sterk

Bonjour à tous

Je découvre les webservice avec Prestashop et j'ai un souci, j'obtient toujours un code 302 lorsque que je tente de mettre à jour une image d'un produit

int(302) string(276) "HTTP/1.1 100 Continue HTTP/1.1 302 Found Date: Sat, 17 Aug 2019 13:40:13 GMT Server: Apache X-Powered-By: PHP/7.0 Location: http://myshop.xyz/shop/index.php?url=images%2Fproducts%2F104954%2F Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 "

J'ai bien généré ma clé api dans l'interface admin

Voici mon code :

 

 $url = 'http://www.myshop/shop';
   $key  = 'XYZXYZXYZXYZXYZXYZXYZXYZ';

    $psProductId = 104954;
    $urlImage = $url.'/api/images/products/'.$psProductId.'/';
   
 
    $image_path = '/home/web/www/shop/img/p/2/6/0/1/2601-large_default.jpg';
    $image_mime = 'image/jpg'; 

   $args['image'] = new CurlFile($image_path, $image_mime);

    
     
   
    $ch = curl_init();
    
   //  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data','Expect:'));
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
    curl_setopt($ch, CURLOPT_URL, $urlImage);
    curl_setopt($ch, CURLOPT_POST, 1);
    
    curl_setopt($ch, CURLOPT_USERPWD, $key.':');
  //curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
  //curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => '@'.$image_path));  //test 2
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('image'=>"@".$image_path.";type=image/jpeg")); //test 3
    $result = curl_exec($ch);
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    //echo curl_error($ch);
   
    var_dump($httpCode);
     var_dump($result);
    
      curl_close($ch);

	if (200 == $httpCode) {
        echo 'Product image was successfully created.';
    }

Je possède Prestashop 1.7.6 et suis hébergé chez OVH  avec du php 5.6

Merci pour tout conseil

 

 

 

 

×
×
  • Create New...