Update stoc Emag prin API

In ultimile versiuni de document Integrare API de la EMAG a aparut posibilitatea de a face update stoc -ului de produse print-o resursa REST .

Copiez aici parte in documentatie precum si continutul documentului explicativ

1.   Updating stock

In order to update only the stock of an offer a REST resource is available

ResourceResource URLMethodAuthorizationHeadersParameters
offer_stockMARKETPLACE_API_URL/offer_stock/{resourceId}PATCHBasic (Base64)Content-Type application/jsonresourceId

The resourceId parameter represents the Seller internal product id. This is the primary key for identifying a product offer.

offer_stockhttp method: PATCH  

Continutul documentului „offer_stock.txt” este postat mai jos (din documentul PDF nu se poate deschide ).

Payload example:
    "stock": 21

Possible responses:

- Request processed:
	Code: 204 No Content
	Body: empty

- Not authorized:
	Code: 403 Forbidden
    "isError": true,
    "messages": [
        "You are not allowed to use this API."
    "results": []

- Invalid url:
	Code: 404 Not Found
    "message": "Invalid URL"

- Offer / resource does not exist:
	Code: 404 Not Found
    "message": "This offer does not exist"

- Invalid request content:
	Code: 400 Bad Request
    "message": "Invalid content"

- Flow validations:
	Code: 400 Bad Request
    "message": "Validation errors in your request",
    "errors": [
            "message": "The offer is included in the active campaign BF, thus the stock has NOT been changed.",
            "field": "stock"

Mai jos este un exemplu de cod php pentru acest apel :

$ch = curl_init();
$data = array ( 'stock' => 7 );
$hash = sha1(http_build_query($data) . sha1('parola'));
$requestData = array(
	'code' => 'api_code',
	'username' => 'username-email',
	'data' => $data,
	'hash' => $hash);

curl_setopt($ch, CURLOPT_URL, 'https://marketplace.emag.ro/api-3/offer_stock/id_produsde modificat');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'username-email'.":".'parola');
curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Basic " . base64_encode('username-email'.":".'parola'),'Content-Type: application/json'));  
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
echo "<p> info de curl " . print_r(curl_getinfo($ch));

Faci un comentariu sau dai un răspuns?