Do this tutorial and you will see - https://alankent.me/2015/07/24/creating-a-new-rest-web-service-in-magento-2/
Specifically follow closely where the array of float is passed through in the body of the HTTP request.
app/code/AlanKent/CalculatorWebService/etc/webapi.xml
<!-- Example: curl http://127.0.0.1/index.php/rest/V1/calculator/add/1/2 -->
<route url="/V1/calculator/add/:num1/:num2" method="GET">
<service class="AlanKent\CalculatorWebService\Api\CalculatorInterface" method="add"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
<!-- Example: curl -d '{"nums":[1.1,2.2,3.3]}' -H 'Content-Type: application/json' http://127.0.0.1/index.php/rest/V1/calculator/sum -->
<route url="/V1/calculator/sum" method="POST">
<service class="AlanKent\CalculatorWebService\Api\CalculatorInterface" method="sum"/>
<resources>
<resource ref="anonymous"/>
</resources>
</route>
Create new customer
$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);
$customerData = [
'customer' => [
"email" => "user@example.com",
"firstname" => "John",
"lastname" => "Doe",
"storeId" => 1,
"websiteId" => 1
],
"password" => "Demo1234"
];
$ch = curl_init("http://magento213/index.php/rest/V1/customers");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customerData));
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 update
$customerData = [
'customer' => [
'id' => 10,
"email" => "user@example.com",
"firstname" => "John2",
"lastname" => "Doe2",
"storeId" => 1,
"websiteId" => 1
],
"password" => "Demo1234"
];
$ch = curl_init("http://magento213/index.php/rest/V1/customers/10");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($customerData));
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);
API List
Best Answer
Create New Customer
For Update Customer
API LIST