JSON API REQUEST PARAMETERS

Written by Saad Rawasia
Posted On Apr, 10, 2018
Following are the parameter which will be sent to JSON API.
  • {user_id}
  • {first_name}
  • {last_name}
  • {gender}
  • {timezone}
  • {fbId}
  • {last_user_msg}
  • {bot_id}
You can access these parameters based on your Request Method i.e, GET or POST. Example Code(PHP):
// GET REQUEST

<?php
   $user_id = $_GET[‘{user_id}’];
?>
// POST REQUEST

<?php
   $json = file_get_contents('php://input');
   $json = json_decode($json,true);
   $first_name = $json['{first_name}'];
   $message = "Hi, ".$first_name.". How are you?";
   echo json_encode(['text'=>$message]);
?>
Entity Values: If you have used Entity in your story, For example, you have created an entity of “color” and user says “I like red color”. The Parameter Key will be “color” and the value will be in array form:
<?php
   $json = file_get_contents('php://input');
   $json = json_decode($json,true);
   $color= $json['{color}'];
   $message = $color." is a beautiful color.";
   echo json_encode(['text'=>$message]);
?>