magento - Create product using Oauth & curl -
After
Trying to create a product using Im RESTful API. RESTCLIENT achieved this functionality using Firefox addon but failed to use the script. I am able to list the products but I am not able to make the product using IM script. Anyone can help me get access denied error
Here's my script
$ url = 'http://magento.com/api/rest/products '? $ Method = 'POST'; # Header and data (this is the dependent API, uses some XML) $ header = array ('Accept: application / json', 'content type: application / json', 'oauth_signature_method: HMAC-SHA1', 'oauth_nonce: ilJuravy9KVYm6R '' oauth_timestamp: 1363848967 ',' oauth_consumer_key: xxx ',' oauth_consumer_secret: yyy ',' oauth_token: zzz ',' oauth_token_secret: xyz ',' oauth_signature: 4admodOkAj2pKwhO5Tk6TEjc7Rg% 3-D ',' oauth_verifier: mrr1350pp0j8hiyv31kzxhko97hyyuwx ',' oauth_version: 1.0 ',); $ Data = json_encode (array ('type_id' = & gt; 'simple', 'attribute_set_id' = & gt; 4, 'SKU' =>. 'Simple' uniqid (), 'weight' => 1 , 'Position' = & gt; 1, 'visibility' = & gt; 4, 'name' = & gt; simple product, 'description' = & gt; 'simple description', 'SHORT_DESCRIPTION' = & gt; 'Simple Short Description', 'Price' = & gt; 99.95, 'tax_class_id' => 1,)); $ Handle = curl_init (); Curl_setopt ($ handle, CURLOPT_URL, $ url); Curl_setopt ($ handle, CURLOPT_HTTPHEADER, $ header); Curl_setopt ($ handle, CURLOPT_RETURNTRANSFER, true); Curl_setopt ($ handle, CURLOPT_SSL_VERIFYHOST, incorrect); Curl_setopt ($ handle, CURLOPT_SSL_VERIFYPEER, incorrect); Switch ($ method) {case 'received': break; Case 'Post': curl_setopt ($ handle, CURLOPT_POST, true); Curl_setopt ($ handle, CURLOPT_POSTFIELDS, $ data); break; Case 'PUT': curl_setopt ($ handle, CURLOPT_CUSTOMREQUEST, 'PUT'); Curl_setopt ($ handle, CURLOPT_POSTFIELDS, $ data); break; Case 'DELETE': curl_setopt ($ handle, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; } Counterpoint $ response = curl_exec ($ handle); Counter code $ code = curl_getinfo ($ handle, CURLINFO_HTTP_CODE); After
You mentioned 3 things to generate and other things are stable like oauth_consumer_key , Oauth_token etc.
1.timestmap 2.signature 3.nonce
See all the things I've generated code below.
$ temporarily = substr (md5 (Unicode ('non-c, true)), 0,16); $ Temprealm = "http: // magentohost / API / Rest / Products"; $ Scope = urlencode ($ temprealm); $ Oauth_version = "1.0"; $ Oauth_signature_method = "HMAC-SHA1"; $ Oauth_consumer_key = "lro2hnoh3c8luvhcr49j6qgygmyvw7e3"; $ Oauth_access_token = "xbqe4wnu3zv357gimpdnuejvcbtk51ni"; $ = Oauth_method "GET"; $ Oauth_timestamp = Time (); $ Algo = "SHA1"; $ Key = "sb88hfdihyg25ipt1by559yzbj2m3861 & amp; s7uhaheu8nrx961oxg6uc3os4zgyc2tm"; // Consumer Secret & amp; The token is done in both the secret / signature $ sign = data = "oauth_consumer_key =" $ oauth_consumer_key. "& Amp; oauth_nonce =" $ temporarily .. "& Oauth_signature_method =" $ oauth_signature_method "& oauth_timestamp =" ... $ Oauth_timestamp "& Oauth_token =" $ oauth_access_token "& oauth_version =" ... $ Oauth_version; $ Send_data = $ oauth_method "& amp;" $ Range "& amp;" Urlencode ($ data). $ Sign = hash_hmac ($ algo, $ send_data, $ key, 1); // Consumer Key and Token Secret is used here $ fin_sign = base64_encode ($ sign); $ Curl = curl_init (); Curl_setopt ($ curl, CURLOPT_HTTPHEADER, array '. Authority: OAuth scope =' $ scope ', oauth_version = "1.0", oauth_signature_method = "HMAC-SHA1", oauth_nonce = "' .. $ temporarily" ", oauth_timestamp = ''. $ Oauth_timestamp. '", Oauth_consumer_key =, oauth_token =, oauth_signature =' $ oauth_consumer_key .. '' $ oauth_access_token. '." "' '))' $ Fin_sign .. '; Curl_setopt ($ curl, CURLOPT_URL, $ temprealm); $ XML = curl_exec ($ curl);
Comments
Post a Comment