Below is the script for order api.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require ('/vendor/autoload.php');
require('/vendor/zendframework/zend-http/src/Headers.php');
require('/vendor/zendframework/zend-http/src/Request.php');
require('/vendor/zendframework/zend-http/src/Response.php');
/*Token Generated from SYstem Integratio*/
$token = '9kvn45tbopelidqj9ddita9rvyujk1tl';
$httpHeaders = new \Zend\Http\Headers();
$httpHeaders->addHeaders([
'Authorization' => 'Bearer ' . $token,
'Accept' => 'application/json',
'Content-Type' => 'application/json'
]);
$request = new \Zend\Http\Request();
$request->setHeaders($httpHeaders);
$request->setUri('http://1270.0.1/magentoce27/index.php/rest/V1/orders/1');
$request->setMethod(\Zend\Http\Request::METHOD_GET);
$client = new \Zend\Http\Client();
$options = [
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => [CURLOPT_FOLLOWLOCATION => true],
'maxredirects' => 0,
'timeout' => 30
];
$client->setOptions($options);
$response = $client->send($request);
echo "<pre>".print_r(json_decode($response->getBody()),true)."</pre>";
?>
Here, is the script for customer api,
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require ('/vendor/autoload.php');
require('/vendor/zendframework/zend-http/src/Headers.php');
require('/vendor/zendframework/zend-http/src/Request.php');
require('/vendor/zendframework/zend-http/src/Response.php');
/*Token Generated from SYstem Integratio*/
$token = '9kvn45tbopelidqj9ddita9rvyujk1tl';
$httpHeaders = new \Zend\Http\Headers();
$httpHeaders->addHeaders([
'Authorization' => 'Bearer ' . $token,
'Accept' => 'application/json',
'Content-Type' => 'application/json'
]);
$request = new \Zend\Http\Request();
$request->setHeaders($httpHeaders);
$request->setUri('http://1270.0.1/magentoce27/index.php/rest/V1/customers/1');
$request->setMethod(\Zend\Http\Request::METHOD_GET);
$client = new \Zend\Http\Client();
$options = [
'adapter' => 'Zend\Http\Client\Adapter\Curl',
'curloptions' => [CURLOPT_FOLLOWLOCATION => true],
'maxredirects' => 0,
'timeout' => 30
];
$client->setOptions($options);
$response = $client->send($request);
echo "<pre>".print_r(json_decode($response->getBody()),true)."</pre>";
?>
Kindly note that you might need to do changes in API as per your requirement.
Also you will need to generate token from admin panel and put that token into script and also change url as per your project setup.
To process the payment you can use the native API of the payment method, but you can use these methods to get the payment methods available and to place an order in Magento using the REST API.
Get Payment Method
curl -g -X GET "XXXXX_STOREURL_XXXXX/index.php/rest/V1/guest-carts/56241bf6bc084cd7589426c8754fc9c5/payment-information" \
-H "Authorization: Bearer XXXXX_TOKEN_XXXXX"
Place Order
curl -g -X PUT "XXXXX_STOREURL_XXXXX/index.php/rest/V1/guest-carts/56241bf6bc084cd7589426c8754fc9c5/order" \
-H "Authorization: Bearer XXXXX_TOKEN_XXXXX" \
-H "Content-Type:application/json" \
-d '
{
"method": {
"method": "checkmo"
}
}
Best Answer
Refer below link for Magento 2.x version. http://devdocs.magento.com/swagger/index_20.html#/
I have used below body for creating customers through Rest Api and it worked properly.
Url : http://www.xxxxxxxx.com/rest/V1/customers
Type: POST
Content-Type : application/json
payload Data:
Response:
Call through postman see example in attachment: