H
H
hhhhhhhoooooottttttttt2022-02-13 14:30:59
API
hhhhhhhoooooottttttttt, 2022-02-13 14:30:59

Can't send ozon-seller curl API request?

$curl = curl_init('https://api-seller.ozon.ru/v1/product/import/stocks');
curl_setopt($curl, CURLOPT_HTTPHEADER, [
      										 'Client-Id:  cID',
    										 'Api-Key:  token',
    										 'Content-Type: application/json'

    										]);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_HEADER, falsse);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$updateFieldsData = array(
  'offer_id' => '4574950',
  'product_id' => 492575182,
  'stock' => 0	
  
);
  $data_item = json_encode($updateFieldsData);
  print_r($data_item);
  curl_setopt($curl, CURLOPT_POSTFIELDS, $data_item);
  $json = curl_exec($curl);
  $err = curl_error($curl);
  print_r($json);
  curl_close($curl);


produces {"result":[]}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rst0, 2022-02-17
@Rst0

curl_setopt($curl, CURLOPT_HEADER, falsse) // < --  SS

Check Client-Id and Api-Key in ' Host : api-seller.ozon.ru '
header
// POST -запрос к серверу
$curl_cookie = '';
$curl_error  = false;
$headers = array(
   'Host: api-seller.ozon.ru',
   'Client-Id:  cID',
   'Api-Key:  token',
   'Content-Type: application/json'
);
$url = 'https://api-seller.ozon.ru/v1/product/import/stocks';
$arguments = array(
  'offer_id' => '4574950',
  'product_id' => 492575182,
  'stock' => 0	
  
);
function web_post( $url, $arguments = [], $headers =  '', $sleep = 0, $timeout = 600 ) {

    global $curl_error,  $curl_cookie; 

    if( $sleep > 0 ){
       sleep( $sleep );
    }

    $ch = curl_init();

    $copt = [ 
       CURLOPT_URL => $url, 
       CURLOPT_COOKIE => $curl_cookie,
       CURLOPT_POST  => 1, 
       CURLOPT_POSTFIELDS  => $arguments,
       CURLOPT_COOKIESESSION  => 1, 
       CURLOPT_SSL_VERIFYHOST => 0, 
       CURLOPT_SSL_VERIFYPEER => 0, 
       CURLOPT_VERBOSE  => 0,
       CURLOPT_FOLLOWLOCATION => 1, 
       CURLOPT_UNRESTRICTED_AUTH => 1,
       CURLOPT_FAILONERROR => 1, 
       CURLOPT_AUTOREFERER  => 1, 
       CURLOPT_TIMEOUT  => $timeout, 
       CURLOPT_CONNECTTIMEOUT => $timeout, 
       CURLOPT_RETURNTRANSFER => 1,
       CURLOPT_HTTPHEADER  => $headers
   ];

   curl_setopt_array($ch,$copt); 

   if(false === ( $data = curl_exec( $ch ))){
        $curl_error = curl_error($ch);
   }
   curl_close($ch);
   return $data; 
}

print_r(web_post( $url, json_encode( $arguments ), $headers));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question