I wonder how do I get pending orders using Magento API with OAuth token?
Thank you,
UPDATED
If I try as follows,
public function index2()
{
$consumerKey = 'kfkhypveth1upv6f4uwy5l9r7tdwmdp0';
$consumerSecret = 't9ire4rup8wre5gbbqt3ic2q2snb6ogs';
$accessToken = '9alfh5bntatd0gk3lwdjxv972erppnmk';
$accessTokenSecret = 'rxmvwjrb9r8qq2hy0e2ijdytk2srrhmc';
$method = 'GET';
$status_field = "searchCriteria[filterGroups][0][filters][0][field]=status";
$status_value = "searchCriteria[filterGroups][0][filters][0][value]=pending";//
$status_condition = "searchCriteria[filterGroups][0][filters][0][condition_type]=eq";
$sc = $status_field . '&' . $status_value . '&' . $status_condition;
$url = "http://127.0.0.1:8080/mg1/index.php/rest/V1/orders/?".$sc;
$data = [
'oauth_consumer_key' => $consumerKey,
'oauth_nonce' => md5(uniqid(rand(), true)),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => time(),
'oauth_token' => $accessToken,
'oauth_version' => '1.0',
];
$data['oauth_signature'] = $this->sign($method, $url, $data, $consumerSecret, $accessTokenSecret);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_HTTPHEADER => [
'Authorization: OAuth ' . http_build_query($data, '', ',')
]
]);
$result = curl_exec($curl);
curl_close($curl);
echo '<pre>';
print_r(json_decode($result,false));
}//end of function
I get following error,
stdClass Object
(
[message] => Invalid signature
[trace] => #0 C:\wamp64\www\mg1\vendor\magento\framework\Oauth\Oauth.php(121): Magento\Framework\Oauth\Oauth->_validateSignature(Array, 't9ire4rup8wre5g...', 'GET', 'http://127.0.0....', 'rxmvwjrb9r8qq2h...')
#1 C:\wamp64\www\mg1\vendor\magento\module-webapi\Model\Authorization\OauthUserContext.php(82): Magento\Framework\Oauth\Oauth->validateAccessTokenRequest(Array, 'http://127.0.0....', 'GET')
#2 C:\wamp64\www\mg1\vendor\magento\module-authorization\Model\CompositeUserContext.php(78): Magento\Webapi\Model\Authorization\OauthUserContext->getUserId()
#3 C:\wamp64\www\mg1\vendor\magento\module-authorization\Model\CompositeUserContext.php(57): Magento\Authorization\Model\CompositeUserContext->getUserContext()
#4 C:\wamp64\www\mg1\vendor\magento\module-webapi\Model\WebapiRoleLocator.php(45): Magento\Authorization\Model\CompositeUserContext->getUserId()
#5 C:\wamp64\www\mg1\vendor\magento\framework\Authorization.php(47): Magento\Webapi\Model\WebapiRoleLocator->getAclRoleId()
#6 C:\wamp64\www\mg1\vendor\magento\framework\Interception\Interceptor.php(74): Magento\Framework\Authorization->isAllowed('Magento_Sales::...', NULL)
#7 C:\wamp64\www\mg1\vendor\magento\framework\Interception\Chain\Chain.php(70): Magento\Framework\Authorization\Interceptor->___callParent('isAllowed', Array)
#8 C:\wamp64\www\mg1\vendor\magento\framework\Interception\Chain\Chain.php(63): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'isAllowed', Object(Magento\Framework\Authorization\Interceptor), Array, 'customerAuthori...')
#9 C:\wamp64\www\mg1\vendor\magento\module-customer\Model\Plugin\CustomerAuthorization.php(58): Magento\Framework\Interception\Chain\Chain->Magento\Framework\Interception\Chain\{closure}('Magento_Sales::...', NULL)
#10 C:\wamp64\www\mg1\vendor\magento\framework\Interception\Chain\Chain.php(67): Magento\Customer\Model\Plugin\CustomerAuthorization->aroundIsAllowed(Object(Magento\Framework\Authorization\Interceptor), Object(Closure), 'Magento_Sales::...', NULL)
#11 C:\wamp64\www\mg1\vendor\magento\framework\Interception\Interceptor.php(138): Magento\Framework\Interception\Chain\Chain->invokeNext('Magento\\Framewo...', 'isAllowed', Object(Magento\Framework\Authorization\Interceptor), Array, 'guestAuthorizat...')
#12 C:\wamp64\www\mg1\vendor\magento\module-webapi\Model\Plugin\GuestAuthorization.php(38): Magento\Framework\Authorization\Interceptor->Magento\Framework\Interception\{closure}('Magento_Sales::...', NULL)
#13 C:\wamp64\www\mg1\vendor\magento\framework\Interception\Interceptor.php(142): Magento\Webapi\Model\Plugin\GuestAuthorization->aroundIsAllowed(Object(Magento\Framework\Authorization\Interceptor), Object(Closure), 'Magento_Sales::...')
#14 C:\wamp64\www\mg1\var\generation\Magento\Framework\Authorization\Interceptor.php(26): Magento\Framework\Authorization\Interceptor->___callPlugins('isAllowed', Array, Array)
#15 C:\wamp64\www\mg1\vendor\magento\framework\Webapi\Authorization.php(37): Magento\Framework\Authorization\Interceptor->isAllowed('Magento_Sales::...')
#16 C:\wamp64\www\mg1\vendor\magento\module-webapi\Controller\Rest\RequestValidator.php(86): Magento\Framework\Webapi\Authorization->isAllowed(Array)
#17 C:\wamp64\www\mg1\vendor\magento\module-webapi\Controller\Rest\RequestValidator.php(70): Magento\Webapi\Controller\Rest\RequestValidator->checkPermissions()
#18 C:\wamp64\www\mg1\vendor\magento\module-webapi\Controller\Rest\InputParamsResolver.php(80): Magento\Webapi\Controller\Rest\RequestValidator->validate()
#19 C:\wamp64\www\mg1\vendor\magento\module-webapi\Controller\Rest.php(299): Magento\Webapi\Controller\Rest\InputParamsResolver->resolve()
#20 C:\wamp64\www\mg1\vendor\magento\module-webapi\Controller\Rest.php(216): Magento\Webapi\Controller\Rest->processApiRequest()
#21 C:\wamp64\www\mg1\var\generation\Magento\Webapi\Controller\Rest\Interceptor.php(37): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))
#22 C:\wamp64\www\mg1\vendor\magento\framework\App\Http.php(135): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))
#23 C:\wamp64\www\mg1\vendor\magento\framework\App\Bootstrap.php(258): Magento\Framework\App\Http->launch()
#24 C:\wamp64\www\mg1\index.php(39): Magento\Framework\App\Bootstrap- >run(Object(Magento\Framework\App\Http))
#25 {main}
)
But if I change the url as
$url = "http://127.0.0.1:8080/mg1/index.php/rest/V1/orders/1";
then I get first order details.
Any idea why?
http://<magento_host>/rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=status& searchCriteria[filter_groups][0][filters][0][value]=pending& searchCriteria[filter_groups][0][filters][0][condition_type]=eq