API Route for User Registration

Sample Code for User Registration via API Routes

PHP Curl

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://mysite.com/wp-json/wpcargo/v1/api/register_user',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_POSTFIELDS => '{
    "signup": {
       "username": "xxxxxyyyy",
       "email": "xxx000000@gmail.com",
       "password": "123456",
       "phone": "123654789",
       "address": "Philippines",
       "city": "Iloilo city1"
    }
}',
  CURLOPT_HTTPHEADER => array(
    'Content-Type: application/json'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

Sample Response:

{
    "code": 406,
    "message": "Email is already exists, please try another email",
    "data": {
        "status": 400
    }
}

PHP HTTP Request2


<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('https://jeffreydula.iloiloadventure.com/wp-json/wpcargo/v1/api/register_user');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Content-Type' => 'application/json'
));
$request->setBody('{
      "signup": {
           "username": "xxxxxyyyy", 
           "email": "xxx000000@gmail.com", 
           "password": "123456", 
           "phone": "123654789", 
           "address": "Philippines", 
           "city": "Iloilo city1"
      }
}');
try {
  $response = $request->send();
  if ($response->getStatus() == 200) {
    echo $response->getBody();
  }
  else {
    echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
    $response->getReasonPhrase();
  }
}
catch(HTTP_Request2_Exception $e) {
  echo 'Error: ' . $e->getMessage();
}

0
    0
    Your Cart
    Your cart is emptyReturn to Shop