Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

REST API - Dos it work? 
 
nafnaf1000
Sr. Member
 
Total Posts:  209
Joined:  2008-02-21
 

Hi,
I am wondering if anyone here has the REST API working and is able to upload and update items on there site?

If so, can you please help me with a walk-through that works as no matter what I try to do I get errors.....

Thanks so much.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Moderator
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

At least give a try first then raise your problem here.
Anyway, you can find the following articles for references:
http://www.magentocommerce.com/api/rest/introduction.html
http://www.aschroder.com/2012/04/introduction-to-the-magento-rest-apis-with-oauth-in-version-1-7/

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
nafnaf1000
Sr. Member
 
Total Posts:  209
Joined:  2008-02-21
 

Thanks for reading my post.

I am using the sample code from the Wiki page to

Create a simple product as an Admin user with OAuth authentication
I named it testapi.php

when I go there redirects me to https://www.sample.com/index.php/admin/oauth_authorize

An error occurred. Your authorization request is invalid.

I have created a customer and rolls and gave user permission.

Thanks for your help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagePsycho
Moderator
 
Avatar
Total Posts:  1702
Joined:  2009-06-23
 

Make sure OAuth is set up with Request engine support php_streams curl.
You can use phpinfo() to make sure of this.l

 
Magento Community Magento Community
Magento Community
Magento Community
 
nafnaf1000
Sr. Member
 
Total Posts:  209
Joined:  2008-02-21
 

ok, so this is what I have

curl
cURL support enabled
cURL Information 7.19.7
Age 3
Features
AsynchDNS No
Debug No
GSS-Negotiate Yes
IDN Yes
IPv6 Yes
Largefile Yes
NTLM Yes
SPNEGO No
SSL Yes
SSPI No
krb4 No
libz Yes
CharConv No
Protocols tftp, ftp, telnet, dict, ldap, ldaps, http, file, https, ftps
Host x86_64-pc-linux-gnu
SSL Version OpenSSL/0.9.8k
ZLib Version 1.2.3.3

and then I have

OAuth
OAuth support enabled
PLAINTEXT support enabled
RSA-SHA1 support enabled
HMAC-SHA1 support enabled
Request engine support php_streams
source version $Id: oauth.c 325799 2012-05-24 21:07:51Z jawed $
version 1.2.3

am I missing something?

Thanks so much

 
Magento Community Magento Community
Magento Community
Magento Community
 
nafnaf1000
Sr. Member
 
Total Posts:  209
Joined:  2008-02-21
 

OK< so just to make sure I was not crazy, I reinstalled magento and started form new.

I am using this code from this page. link

I uploaded this cpde and saved it as testapi.php

<?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$consumerSecretOAUTH_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$productDataOAUTH_HTTP_METHOD_POST$headers);
        
print_r($oauthClient->getLastResponseInfo());
    
}
catch (OAuthException $e{
    print_r
($e);
}

I go to domain.com/testapi.php

it takes me to

http://www.TEST.com/admin/oauth_authorize?oauth_token=8kpkkd6m5any6vc3fdsddqq4tcgxyt4

Authorize application
test requests access to your account

After authorization application will have access to you account
.

After I click Authorize it takes me to http://www.TEST.com/oauth_admin.php?oauth_token=8kpkkd6m5acny6vc3fdsddqq4tcgxyt4&oauth;_verifier=6ank1aeergj6g2lmlb14ozeoxn5fkdsg

Then all i get is

404 Not found.

Whoops, our bad…

The page you requested was not found, and we have a fine guess why.

If you typed the URL directly, please make sure the spelling is correct.
If you clicked on a link to get here, the link is outdated.

What can you do?
Have no fear, help is near! There are many ways you can get back on track with Magento Store.

Go back to the previous page.
Use the search bar at the top of the page to search for your products.
Follow these links to get you back on track!
Store Home | My Account

Compare Products

You have no items to compare.
My Cart

You have no items in your shopping cart.
Keep your eyes open for our special Back to School items and save A LOT!
Community Poll

What is your favorite color

Green
Red
Black
Magenta

did i miss something in the setup?

thanks,.

 
Magento Community Magento Community
Magento Community
Magento Community
 
palanikumark
Member
 
Total Posts:  66
Joined:  2010-01-03
 

Me too getting the same error. Did you resolve this issue?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top