I am very new to developing against the Magento API and know nothing about this platform so I realize this is a silly question.
I have managed to connect to our test store and collect the admin token for the REST API requests, but every subsequent request to an API entry point returns "404 page not found".
I am not getting an authorization error so I am assuming that I have added the auth header to the requests correctly. Is there a way to verify the rest API entry points from the admin console? I want to make sure that the URI in the requests is correct.
I am using something like...
https://<hostname>/rest/V1/orders
Thanks
-Sean
Solved! Go to Solution.
I see what I was doing wrong. The HTTP
@sean_bennington wrote:I think the issue is related to the query string being passed. I was able to get the store to respond with a simple request
GET /rest/V1/orders?searchCriteria[currentPage] HTTP/1.1
Host: magdev.val-co.store
Authorization: Bearer ym16qhi0XXXXXXXXXXuedgn8g8iemj9k
Accept: application/json
cache-control: no-cache
Postman-Token: 259ba0c7-1096-4114-b2d2-12301ef98eda
but something with a more involved filter ...
PUT /rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=updated_at& searchCriteria[filter_groups][0][filters][0][value]=2019-01-01T14:01:54.9571247Z& searchCriteria[filter_groups][0][filters][0][condition_type]=gt
"filter_groups": [
{
"filters": [
{
"field": "updated_at",
"value": "2019-01-01T14:01:54.9571247Z",
"condition_type": "gt"
},
]
},
],
} HTTP/1.1
Host: magdev.val-co.store
Authorization: Bearer ym16qhi0XXXXXXXXXXuedgn8g8iemj9k
Accept: application/json
cache-control: no-cache
Postman-Token: e7178c2f-ac69-42b6-b16a-afe5700bd33c
Returns...
{
"message": "Request does not match any route.",
"trace": null
}
Is there something I am missing in the filter query parameters?
Thanks
-Sean
verb was incorrect. Doh! >.<
Hello @sean_bennington
Fir you will require to get the accesstoken of the admin, and then when you call the API of orders then you will require to pass that token into the header.
Below is the example :
$userData = array("username" => "admin", "password" => "admin123"); $ch = curl_init("http://magento213/index.php/rest/V1/integration/admin/token"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData)))); $token = curl_exec($ch); $ch = curl_init("http://magento213/index.php/rest/V1/orders/1"); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token))); $result = curl_exec($ch); $result = json_decode($result, 1); echo '<pre>';print_r($result);
For more details refer this link - https://magento.stackexchange.com/questions/154198/magento-2-how-to-get-order-information-using-rest...
Also on a separate note - 404 error you are facing it means you are not using the correct URL, or the URL which you are using is not the perfect one - so kindly check the URL and its parameters for the same.
Hope it helps !
I think the issue is related to the query string being passed. I was able to get the store to respond with a simple request
GET /rest/V1/orders?searchCriteria[currentPage] HTTP/1.1
Host: magdev.val-co.store
Authorization: Bearer ym16qhi0XXXXXXXXXXuedgn8g8iemj9k
Accept: application/json
cache-control: no-cache
Postman-Token: 259ba0c7-1096-4114-b2d2-12301ef98eda
but something with a more involved filter ...
PUT /rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=updated_at& searchCriteria[filter_groups][0][filters][0][value]=2019-01-01T14:01:54.9571247Z& searchCriteria[filter_groups][0][filters][0][condition_type]=gt
"filter_groups": [
{
"filters": [
{
"field": "updated_at",
"value": "2019-01-01T14:01:54.9571247Z",
"condition_type": "gt"
},
]
},
],
} HTTP/1.1
Host: magdev.val-co.store
Authorization: Bearer ym16qhi0XXXXXXXXXXuedgn8g8iemj9k
Accept: application/json
cache-control: no-cache
Postman-Token: e7178c2f-ac69-42b6-b16a-afe5700bd33c
Returns...
{
"message": "Request does not match any route.",
"trace": null
}
Is there something I am missing in the filter query parameters?
Thanks
-Sean
I see what I was doing wrong. The HTTP
@sean_bennington wrote:I think the issue is related to the query string being passed. I was able to get the store to respond with a simple request
GET /rest/V1/orders?searchCriteria[currentPage] HTTP/1.1
Host: magdev.val-co.store
Authorization: Bearer ym16qhi0XXXXXXXXXXuedgn8g8iemj9k
Accept: application/json
cache-control: no-cache
Postman-Token: 259ba0c7-1096-4114-b2d2-12301ef98eda
but something with a more involved filter ...
PUT /rest/V1/orders?searchCriteria[filter_groups][0][filters][0][field]=updated_at& searchCriteria[filter_groups][0][filters][0][value]=2019-01-01T14:01:54.9571247Z& searchCriteria[filter_groups][0][filters][0][condition_type]=gt
"filter_groups": [
{
"filters": [
{
"field": "updated_at",
"value": "2019-01-01T14:01:54.9571247Z",
"condition_type": "gt"
},
]
},
],
} HTTP/1.1
Host: magdev.val-co.store
Authorization: Bearer ym16qhi0XXXXXXXXXXuedgn8g8iemj9k
Accept: application/json
cache-control: no-cache
Postman-Token: e7178c2f-ac69-42b6-b16a-afe5700bd33c
Returns...
{
"message": "Request does not match any route.",
"trace": null
}
Is there something I am missing in the filter query parameters?
Thanks
-Sean
verb was incorrect. Doh! >.<