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.

ResourceExampleContext
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
	Body:
{
    "isError": true,
    "messages": [
        "You are not allowed to use this API."
    ],
    "results": []
}

- Invalid url:
	Code: 404 Not Found
	Body:
{
    "message": "Invalid URL"
}

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

- Invalid request content:
	Code: 400 Bad Request
	Body:
{
    "message": "Invalid content"
}

- Flow validations:
	Code: 400 Bad Request
	Body:
{
    "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_CUSTOMREQUEST, 'PATCH');
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);
print($result);
echo "<p> info de curl " . print_r(curl_getinfo($ch));

This Post Has 2 Comments

  1. Mihai

    Salut,

    Am testat metoda si functioneaza, exista si vreun rate limit pentru update-ul de stoc?
    Nu am gasit in alta parte documentatie pentru metoda asta si nici nu am cum sa testez in masa decat in productie.

    Multumesc

    1. admin

      Buna Mihai,
      Multumesc pentru confirmare. eu folosesc aceasta metoda in productie sa zic asa si nu am vazut limitari.
      Multumesc,
      Daniel

Lasă un răspuns