回答
所以你必须只通过产品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产品品牌