回答
所以你必須只通過產品ID您可以在下面使用GET產品的細節,在這裏:productId
動態變量,或者您也可以通過SKU
GET http://magentohost/api/rest/products/:productId
產品的具體Magento的REST API請求
檢索產品列表,創建,更新或刪除產品。你會打電話給Magento的REST API是這樣的:
http://www.my-magento-store.com/api/rest/products
產品分類 檢索分配給產品類別列表,分配和從具體的產品取消指定類別/。你會打電話給Magento的REST API是這樣的:
http://www.my-magento-store.com/api/rest/products/:productId/categories
產品圖片
檢索分配到產品圖片列表,添加,更新,並從具體的產品中刪除圖像/。你會打電話給Magento的REST API是這樣的:
http://www.my-magento-store.com/api/rest/products/:productId/images
Magento的REST API的例子:
$callbackUrl = "http://www.my-magento-store.com/oauth_admin.php";
$temporaryCredentialsRequestUrl = "http://www.my-magento-store.com/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://www.my-magento-store.com/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://www.my-magento-store.com/oauth/token';
$apiUrl = 'http://www.my-magento-store.com/api/rest';
$consumerKey = '{Consumer Key}';
$consumerSecret = '{Consumer Secret}';
session_start();
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
$_SESSION['state'] = 0;
}
try {
$authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
$oauthClient->enableDebug();
if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
$requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
$_SESSION['secret'] = $requestToken['oauth_token_secret'];
$_SESSION['state'] = 1;
header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
exit;
} else if ($_SESSION['state'] == 1) {
$oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
$accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
$_SESSION['state'] = 2;
$_SESSION['token'] = $accessToken['oauth_token'];
$_SESSION['secret'] = $accessToken['oauth_token_secret'];
header('Location: ' . $callbackUrl);
exit;
} else {
$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
$resourceUrl = "$apiUrl/products";
$productData = json_encode(array(
'type_id' => 'simple',
'attribute_set_id' => 4,
'sku' => 'simple' . uniqid(),
'weight' => 1,
'status' => 1,
'visibility' => 4,
'name' => 'My Product Name',
'description' => 'My Product Description',
'short_description' => 'My Products Short Description',
'price' => 6.99,
'tax_class_id' => 0,
));
$headers = array('Content-Type' => 'application/json');
$oauthClient->fetch($resourceUrl, $productData, OAUTH_HTTP_METHOD_POST, $headers);
print_r($oauthClient->getLastResponseInfo());
}
} catch (OAuthException $e) {
print_r($e);
}
正如你可以在上面給出的代碼中看到,你必須聲明你的連接上,認證令牌。由於此示例使用oAuth身份驗證,因此在撥打http://www.my-magento-store.com/api/rest/之前,您需要在主機,客戶和密鑰上指定它的位置。如果一切正常,您可以創建一個簡單產品的JSON陣列,以便現場推送。
現在,讓我們來看看另一個例子
$callbackUrl = "http://www.my-magento-store.com/oauth_customer.php";
$temporaryCredentialsRequestUrl = "http://www.my-magento-store.com/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://www.my-magento-store.com/oauth/authorize';
$accessTokenRequestUrl = 'http://www.my-magento-store.com/oauth/token';
$apiUrl = 'http://www.my-magento-store.com/api/rest';
$consumerKey = '{Consumer Key}';
$consumerSecret = '{Consumer Secret}';
session_start();
if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
$_SESSION['state'] = 0;
}
try {
$authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
$oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
$oauthClient->enableDebug();
if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
$requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
$_SESSION['secret'] = $requestToken['oauth_token_secret'];
$_SESSION['state'] = 1;
header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
exit;
} else if ($_SESSION['state'] == 1) {
$oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
$accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
$_SESSION['state'] = 2;
$_SESSION['token'] = $accessToken['oauth_token'];
$_SESSION['secret'] = $accessToken['oauth_token_secret'];
header('Location: ' . $callbackUrl);
exit;
} else {
$oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
$resourceUrl = "$apiUrl/products";
$oauthClient->fetch($resourceUrl);
$productsList = json_decode($oauthClient->getLastResponse());
print_r($productsList);
}
} catch (OAuthException $e) {
print_r($e);
}
上面的代碼將檢索所有產品的列表,通過Magento的REST API客戶。請記住,管理員和客戶用戶類型需要授權標頭。如果要爲客人實現REST,你可以這樣做:
http://www.my-magento-store.com/api/rest/products?limit=1
這將導致以下XML輸出
<?xml version="1.0"?>
<magento_api>
<data_item>
<entity_id>18</entity_id>
<type_id>simple</type_id>
<sku>SKU Number</sku>
<description>Your Product Description
</description>
<meta_keyword>Meta Keywords </meta_keyword>
<short_description>Short Description</short_description>
<name>Product Name</name>
<meta_title>Product Title</meta_title>
<meta_description>Meta Desciption</meta_description>
<regular_price_with_tax>Regular Price of the product </regular_price_with_tax>
<regular_price_without_tax>Price without Tax</regular_price_without_tax>
<final_price_with_tax>Final Price With Tax</final_price_with_tax>
<final_price_without_tax>Final Price without Tax</final_price_without_tax>
<is_saleable>1</is_saleable>
<image_url>Path of the product image</image_url>
</data_item>
</magento_api>
同樣,你可以調用REST API的URL獲取特定的XML數據使用限制參數,默認值爲每個請求10個產品,但一個請求最多隻能請求100個產品。要獲得下一組結果,請撥打電話:
http://www.my-magento-store.com/api/rest/products?page=2&limit=10
我希望這足以開始使用Magento REST API。
- 1. 如何獲得Magento的產品ID,而與REST API創建ID
- 2. 如何獲得magento observer中的產品詳細信息(Order Save)
- 3. 如何從Magento Community Edition 1.6獲得產品信息
- 4. Magento的API調用用於獲取產品信息
- 5. 如何使用Magento的API來獲取產品的審查和評價信息
- 6. 從Solr獲取Magento產品信息
- 7. WooCommerce Rest API通過slug獲得產品
- 8. Magento - 從購物車項目中獲得產品信息
- 9. 如何在magento 1.7中獲得多個產品詳細信息1.7
- 10. 如何從magento中的產品url密鑰獲取產品詳細信息?
- 11. 使用runQuery獲取產品API詳細信息(3DCART高級API)
- 12. magento 2 rest api產品過濾器
- 13. Magento rest api只提供10種產品
- 14. 如何調用產品信息?
- 15. 如何使用magento中的產品ID獲得產品可用性?
- 16. Magento的:移動產品組信息在產品視圖底部
- 17. 如何在magento 2的產品詳細信息頁面中使用產品ID獲取類別集合?
- 18. 如何使用mysql查詢從Magento數據庫獲取產品詳細信息?
- 19. 如何使用Magento中的集合獲取產品類別信息
- 20. 獲取產品信息/ NET
- 21. 如何從magento2或magento2.0的產品ID獲取產品信息?
- 22. 使用亞馬遜API獲取產品詳細信息
- 23. 如何使用Magento Rest API
- 24. 從分類頁面獲取一個產品的信息在Magento
- 25. 如何在Magento中翻譯產品名稱和信息
- 26. 如何獲得網站產品詳細信息的鏈接?
- 27. 如何獲得隨機產品,如果我沒有在magento的相關產品
- 28. 如何獲得亞馬遜的產品廣告API的運輸信息
- 29. Magento API特定商店視圖的產品信息?
- 30. 我如何獲得所有Magento產品品牌