0

We have tried to get Customer Data using the below URL. we have got the below error URL: http://127.0.0.1/magento1940/api/rest/customer/:3

https://i.sstatic.net/gpqLL.png

asked Sep 24, 2020 at 13:26
1

1 Answer 1

0

First, Your URL Request should be: GET http://magentohost/api/rest/customers/2

Finally, You are using REST API on Magento 1, you have to request a authenticate before call the API function.

  • Preparing REST API for the Third-Party Application

Preparing REST API for the Third-Party Application

These steps are required for utilizing REST API resources:

  • Set up permissions for REST resource operations from Magento Admin Panel.
  • Configure the attributes for different users types in Magento Admin Panel. There are 3 different types of users in accessing the data: Admin, Customer, and Guest. Admin is the backend logged in user, Customer is the fronted logged in user, and Guest is a non-logged in fronted user.

PHP EXAMPLES:

<?php
/**
* Example of simple product POST using Admin account via Magento REST API. OAuth authorization is used
*/
$callbackUrl = "http://yourhost/oauth_admin.php";
$temporaryCredentialsRequestUrl = "http://magentohost/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
$adminAuthorizationUrl = 'http://magentohost/admin/oauth_authorize';
$accessTokenRequestUrl = 'http://magentohost/oauth/token';
$apiUrl = 'http://magentohost/api/rest';
$consumerKey = 'yourconsumerkey';
$consumerSecret = 'yourconsumersecret';
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' => 'Simple Product',
 'description' => 'Simple Description',
 'short_description' => 'Simple Short Description',
 'price' => 99.95,
 '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);
}

Check the detail document here: Magento 1.x REST API

Vivek Kumar
5,7932 gold badges26 silver badges55 bronze badges
answered Sep 25, 2020 at 6:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.