Skip to main content
added 1 character in body
Source Link
Jeff Yu
  • 136
  • 9

I just use API call to get the stock created or updated. code is following:

$access_token = '4v81lfihtkqanfdr6798zj352qyuyx1x';

$url = 'http://magento2.local/index.php/rest/V1/inventory/source-items';

$ch = curl_init($url);

$body = json_encode(['sourceItems' =>[
        ['source_code' => 'default', 'sku' => '24-MB01', 'quantity'=>555, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB01', 'quantity' => 222, 'status' => 1],
        ['source_code' => 'default', 'sku' => '24-MB04', 'quantity'=>444, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB04', 'quantity' => 111, 'status' => 1],
        ['source_code' => 'default', 'sku' => '24-MB03', 'quantity'=>333, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB03', 'quantity' => 111, 'status' => 1],
]]);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . $access_token));

$result = curl_exec($ch);

var_dump($result);

I just use API call to get the stock created or updated. code is following:

$access_token = '4v81lfihtkqanfdr6798zj352qyuyx1x';

$url = 'http://magento2.local/index.php/rest/V1/inventory/source-items';

$ch = curl_init($url);

$body = json_encode(['sourceItems' =>[
        ['source_code' => 'default', 'sku' => '24-MB01', 'quantity'=>555, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB01', 'quantity' => 222, 'status' => 1],
        ['source_code' => 'default', 'sku' => '24-MB04', 'quantity'=>444, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB04', 'quantity' => 111, 'status' => 1],
        ['source_code' => 'default', 'sku' => '24-MB03', 'quantity'=>333, 'status'=>1],
       ['source_code' => 'la', 'sku' => '24-MB03', 'quantity' => 111, 'status' => 1],
]]);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . $access_token));

$result = curl_exec($ch);

var_dump($result);

I just use API call to get the stock created or updated. code is following:

$access_token = '4v81lfihtkqanfdr6798zj352qyuyx1x';

$url = 'http://magento2.local/index.php/rest/V1/inventory/source-items';

$ch = curl_init($url);

$body = json_encode(['sourceItems' =>[
        ['source_code' => 'default', 'sku' => '24-MB01', 'quantity'=>555, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB01', 'quantity' => 222, 'status' => 1],
        ['source_code' => 'default', 'sku' => '24-MB04', 'quantity'=>444, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB04', 'quantity' => 111, 'status' => 1],
        ['source_code' => 'default', 'sku' => '24-MB03', 'quantity'=>333, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB03', 'quantity' => 111, 'status' => 1],
]]);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . $access_token));

$result = curl_exec($ch);

var_dump($result);
Source Link
Jeff Yu
  • 136
  • 9

I just use API call to get the stock created or updated. code is following:

$access_token = '4v81lfihtkqanfdr6798zj352qyuyx1x';

$url = 'http://magento2.local/index.php/rest/V1/inventory/source-items';

$ch = curl_init($url);

$body = json_encode(['sourceItems' =>[
        ['source_code' => 'default', 'sku' => '24-MB01', 'quantity'=>555, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB01', 'quantity' => 222, 'status' => 1],
        ['source_code' => 'default', 'sku' => '24-MB04', 'quantity'=>444, 'status'=>1],
        ['source_code' => 'la', 'sku' => '24-MB04', 'quantity' => 111, 'status' => 1],
        ['source_code' => 'default', 'sku' => '24-MB03', 'quantity'=>333, 'status'=>1],
       ['source_code' => 'la', 'sku' => '24-MB03', 'quantity' => 111, 'status' => 1],
]]);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer ' . $access_token));

$result = curl_exec($ch);

var_dump($result);