Skip to main content
4 of 5
edited title
BornCoder
  • 1.5k
  • 5
  • 20
  • 46

Magento 2 Rest API: create / update order,customer information

I want to create and update customers, order in Magento-2. But I am facing problem in how to pass data to create customer. Can anyone give me an example for this?

I am passing data like:

$cusData = "rest/V1/customers/{'customers': {'customer':{'email':'[email protected]','firstname':'Jhon','lastname':'test'}}}";

$cusMethod = 'PUT';

$cusJsonData = getData($token,$cusData,$cusMethod);

function getData($token,$data,$method)
{
    try{
        $requestUrl = BASEURL.$data;
        $ch = curl_init($requestUrl);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));
        return curl_exec($ch);
    }catch(Exception $e){
        echo $e->getMessage();
    }
}   
BornCoder
  • 1.5k
  • 5
  • 20
  • 46