The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.
 
 
Thread Tools Display Modes
  #1  
Old 11-23-2015, 01:50 PM
Grip Power Pads Corp's Avatar
Grip Power Pads Corp is offline
 
Join Date: Aug 2012
Location: USA NEW YORK
Posts: 23
Send a message via ICQ to Grip Power Pads Corp
Default

Grant Type Error getting in API Call for getting access token curl


Hi,

I am following your docs listed here http://api.ecwid.com/

and followed step by steps as mentioned above and I am able to get code in first step and when I make POST call to get access token, I am getting following error

[error] => invalid_request
[error_description] => One of the request parameters is missing or invalid


My CURL Request
$client_id = CLIENTID;
$client_secret = CLIENTSECRET;
$redirect_uri = "http://www.naveedmetlo.com/jet/ecwid/auth/token.php";
$grant_type = "authorization_code";
$code = $_REQUEST['code'];
$fields = array('client_id' => urlencode($client_id), 'client_secret' => urlencode($client_secret), 'code' => urlencode($code), 'redirect_uri' => urlencode($redirect_uri), 'grant_type' => urlencode($grant_type));

$url = "https://my.ecwid.com/api/oauth/token";

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

$result = curl_exec($ch);
$decoded = json_decode($result);
echo "<h3>CURL Response </h3><pre>"; print_r($decoded); echo "</pre>";

//close connection
curl_close($ch);

Any Help would be really appreciated.
  #2  
Old 11-24-2015, 09:32 AM
Rick G's Avatar
Rick G Rick G is offline
Ecwid Team
 
Join Date: Jun 2014
Posts: 1,271
Default

Quote:
Originally Posted by Grip Power Pads Corp View Post
Hi,

I am following your docs listed here http://api.ecwid.com/

and followed step by steps as mentioned above and I am able to get code in first step and when I make POST call to get access token, I am getting following error

[error] => invalid_request
[error_description] => One of the request parameters is missing or invalid


My CURL Request
$client_id = CLIENTID;
$client_secret = CLIENTSECRET;
$redirect_uri = "http://www.naveedmetlo.com/jet/ecwid/auth/token.php";
$grant_type = "authorization_code";
$code = $_REQUEST['code'];
$fields = array('client_id' => urlencode($client_id), 'client_secret' => urlencode($client_secret), 'code' => urlencode($code), 'redirect_uri' => urlencode($redirect_uri), 'grant_type' => urlencode($grant_type));

$url = "https://my.ecwid.com/api/oauth/token";

//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

$result = curl_exec($ch);
$decoded = json_decode($result);
echo "<h3>CURL Response </h3><pre>"; print_r($decoded); echo "</pre>";

//close connection
curl_close($ch);

Any Help would be really appreciated.
Hi,

Thank you for contacting us.

You also contacted us via email and I have replied to you there, please check your inbox.

As for the error message, it happens when one of your request parameters is incorrect. I tested the exact code that you provided with the details for my test application and I was able to successfully get the Access token for my store: http://take.ms/eVtdc

So please recheck the fields that you are sending in the URL request, especially make sure that:
- $client_id and $client_secret have String type
- The redirect URL is the same as in the step 1
http://developers.ecwid.com/api-docu...t-access-token

Thank you.
__________________
Ecwid API and App Market Team
Ecwid Developer Website

Last edited by Vitaliy G; 01-04-2016 at 12:22 PM.
  #3  
Old 01-07-2016, 07:09 PM
FV Hard Merchandise's Avatar
FV Hard Merchandise FV Hard Merchandise is offline
 
Join Date: Feb 2012
Posts: 10
Default

Receiving the same error. I think mine has to do with the redirect_uri, as I don't need this for my application as it is a selfhosted web app.

I have even tried the code as above, and omitted the redirect_uri and same error.

CURL Response

stdClass Object
(
[error] => invalid_request
[error_description] => One of the request parameters is missing or invalid
)
  #4  
Old 01-07-2016, 08:07 PM
FV Hard Merchandise's Avatar
FV Hard Merchandise FV Hard Merchandise is offline
 
Join Date: Feb 2012
Posts: 10
Default

I was missing
Code:
"urn:ietf:wg:oauth:2.0:oob"
for the redirect_uri.

Sorry. Thanks.
Ryan

Last edited by ginger; 01-08-2016 at 12:21 PM.
The Following User Says Thank You to FV Hard Merchandise For This Useful Post:
Rick G (01-08-2016)
  #5  
Old 01-08-2016, 12:21 PM
ginger's Avatar
ginger ginger is offline
Ecwid Team
 
Join Date: Sep 2014
Posts: 714
Default

Quote:
Originally Posted by FV Hard Merchandise View Post
I was missing for the redirect_uri.

Sorry. Thanks.
Ryan
Thank you for sharing your solution. It will be helpful for others, viewing this thread.
__________________
Xena S.
Ecwid Customer Care Team

Help Center

⬇ Please click Thanks if my reply helped you.
 
The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.

Tags
curl, php

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:25 PM.
Powered by vBulletin® Version 3.8.11. Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.