I want so connect an external website with a moodle-system. I've already set up the webService and created a token to get access.
I've followed http://www.rumours.co.nz/manuals/using_moodle_web_services.htm set up but in contrast i wanted to realise the connection via REST as in https://github.com/moodlehq/sample-ws-clients/find/master
My approach is to have a moodle class which will handle the data exchange. In first place i just wanted to try to create some new hard coded Users via the webService but it fails with the Moodle-Response:
"invalidrecord Can not find data record in database table external_functions. "
Which seems to me as if i the call was successfully but moodle has a problem to find the "core_user_create_users" function. I've checked the local moodle Database and in the table external_functions is an entry for "core_user_create_users" so i'm kind of confused where moodle doesn't know what to do.
Thats my class:
require_once (DOCUMENT_ROOT.'/tcm/api/moodle/curl.php');
class Moodle {
private $token;
private $domainName; // 'local.moodle.dev';
private $serverUrl;
public function __construct($token, $domainName) {
$this->token = $token;
$this->domainName = $domainName;
$this->serverUrl = $this->domainName . '/webservice/rest/server.php' . '?wstoken=' . $this->token;
echo "initialize Service: $this->serverUrl </br>";
}
public function createUser() {
$functionName = 'core_user_create_users';
/// PARAMETERS - NEED TO BE CHANGED IF YOU CALL A DIFFERENT FUNCTION
$user1 = new stdClass();
$user1->username = 'testusername1';
$user1->password = 'testpassword1';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = 'testidnumber1';
$user1->lang = 'en';
$user1->theme = 'standard';
$user1->timezone = '-12.5';
$user1->mailformat = 0;
$user1->description = 'Hello World!';
$user1->city = 'testcity1';
$user1->country = 'au';
$preferencename1 = 'preference1';
$preferencename2 = 'preference2';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'preferencevalue1'),
array('type' => $preferencename2, 'value' => 'preferencevalue2'));
$user2 = new stdClass();
$user2->username = 'testusername2';
$user2->password = 'testpassword2';
$user2->firstname = 'testfirstname2';
$user2->lastname = 'testlastname2';
$user2->email = 'testemail2#moodle.com';
$user2->timezone = 'Pacific/Port_Moresby';
$users = array($user1, $user2);
$params = array('users' => $users);
/// REST CALL
$serverurl = $this->serverUrl . '&wsfunction=' . $functionName;
require_once (DOCUMENT_ROOT.'/tcm/api/moodle/curl.php');
$curl = new curl;
//if rest format == 'xml', then we do not add the param for backward compatibility with Moodle < 2.2
$restformat = "json";
$resp = $curl->post($serverurl . $restformat, $params);
//print_r($resp);
echo '</br>*************Server Response*************</br>';
var_dump($resp);
}
}
I'm using the curl class from the same github-project which i posted above - moodle is linkng to it in their Documentation..
docs.moodle.org/dev/Creating_a_web_service_client
The entry point of my call is hardcoded right now:
<?php
include_once (DOCUMENT_ROOT.'/tcm/api/moodle/moodle.php');
//entry point of code
if (isset($_POST)){
//token and domain would be in $_POST
$bla = new Moodle('0b5a1e98061c5f7fb70fc3b42af6bfc4', 'local.moodle.dev');
$bla->createUser();
}
Does anyone know how to solve the "invalidrecord Can not find data record in database table external_functions" error or has a different approach/suggestion how i can create my users remotely??
Thanks in advance
I got it finally working with the following code:
class Moodle {
private $token; //'0b5a1e98061c5f7fb70fc3b42af6bfc4';
private $domainName; // 'http://local.moodle.dev';
private $serverUrl;
public $error;
public function __construct($token, $domainName) {
$this->token = $token;
$this->domainName = $domainName;
$this->serverUrl = $this->domainName . '/webservice/rest/server.php' . '?wstoken=' . $this->token;
echo "initialize Service: $this->serverUrl </br>";
}
public function createUser() {
$functionName = 'core_user_create_users';
$user1 = new stdClass();
$user1->username = 'testusername1';
$user1->password = 'Uk3#0d5w';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = '';
$user1->lang = 'en';
$user1->timezone = 'Australia/Sydney';
$user1->mailformat = 0;
$user1->description = '';
$user1->city = '';
$user1->country = 'AU'; //list of abrevations is in yourmoodle/lang/en/countries
$preferencename1 = 'auth_forcepasswordchange';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'true')
);
$users = array($user1);
$params = array('users' => $users);
/// REST CALL
$restformat = "json";
$serverurl = $this->serverUrl . '&wsfunction=' . $functionName. '&moodlewsrestformat=' . $restformat;
require_once (DOCUMENT_ROOT . '/tcm/api/moodle/curl.php');
$curl = new curl();
$resp = $curl->post($serverurl, $params);
echo '</br>************************** Server Response createUser()**************************</br></br>';
echo $serverurl . '</br></br>';
var_dump($resp);
}
}
Info:
For all moodle beginners.. Activating the moodle Debug messages helps a bit. You'll receive an additional error information in the response returned form the server.
Moodle -> Site Administration -> Development -> Debugging -> Debug Messages
Select: DEVELOPER:extra Moodle debug messages for developers
Related
Please help me to sort out this problem
I am getting this error.
[faultstring] => System.NullPointerException: Attempt to de-reference a null object
I am using custom object integration for Sales force.
require_once ('soapclient/SforcePartnerClient.php');
require_once ('soapclient/SforceHeaderOptions.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySforceConnection->createConnection("soapclient/partnerwsdl-sb.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);
// Define constants for the web service. We'll use these later
$parsedURL = parse_url($mySforceConnection->getLocation());
define ("_SFDC_SERVER_", substr($parsedURL['host'],0,strpos($parsedURL['host'], '.')));
define ("_WS_NAME_", 'WebToLeadServices');
define ("_WS_WSDL_", 'soapclient/WebToLeadServices-SB-V1.1.xml');
define ("_WS_ENDPOINT_", 'https://' . _SFDC_SERVER_ . '.salesforce.com/services/wsdl/class/' . _WS_NAME_);
define ("_WS_NAMESPACE_", 'http://soap.sforce.com/schemas/class/' . _WS_NAME_);
// SOAP Client for Web Service
$client = new SoapClient(_WS_WSDL_);
$sforce_header = new SoapHeader(_WS_NAMESPACE_, "SessionHeader", array("sessionId" => $mySforceConnection->getSessionId()));
$client->__setSoapHeaders(array($sforce_header));
$sObject = new stdclass();
$sObject->fullName = 'Sunil';
$sObject->country = 'India';
$sObject->budget = '1';
$sObject->type = 'Contact';
$sObject->dialingCode = '91';
$sObject->emailAddress = "XXXX";
$sObject->mobileNumber = "XXXXXXXX";
$sObject->source = "google";
$sObject->projectInterested = "Project";
$sObject->capturePoint = "XXXX.php";
$sObject->IPAddress = "XXXX";
$sObject->webbannerSource = "google";
$sObject->webbannerSize = "twitter";
$createResponse = $client->createLeadFromWeb(array($sObject));
} catch (Exception $e) {
echo '<pre>';
print_r($e);
echo '</pre>';
}
?>
</pre>
I have got the solution for it
We need to pass the variable like this with required field.
and its working
$lead = new StdClass();
$lead->fullName = 'sunil';
$lead->mobileNumber = "1234567896";
$lead->emailAddress = "sunil#example.in";
$lead->source = "DIGITAL MARKETING";
$leadData = array('wl'=>$lead);
$response = $client->createLeadfromWeb($leadData);
I am trying to send a curl request to moodle using drupal.But each tiem i run this code i get an error message that function name must be a string.I have tried everything but nothing is working.Can anybody please help me?
function form_fun_cake_submit(&$form, &$form_state) {
$serverUrl=' http://localhost/moodle/my/webservice/rest/server.php?wstoken=d90b5d90db13711d12df525366f15db1';
$functionName = 'core_user_create_users';
$user1 = new stdClass();
$user1->username = 'testusername1';
$user1->password = 'Uk3#0d5w';
$user1->firstname = 'testfirstname1';
$user1->lastname = 'testlastname1';
$user1->email = 'testemail1#moodle.com';
$user1->auth = 'manual';
$user1->idnumber = '';
$user1->lang = 'en';
$user1->timezone = 'Australia/Sydney';
$user1->mailformat = 0;
$user1->description = '';
$user1->city = '';
$user1->country = 'AU'; //list of abrevations is in yourmoodle/lang/en/countries
$preferencename1 = 'auth_forcepasswordchange';
$user1->preferences = array(
array('type' => $preferencename1, 'value' => 'true')
);
$users = array($user1);
$params = array('users' => $users);
/// REST CALL
$rest_format = 'json';
//$server_url = $domain_name . '/webservice/rest/server.php' . '?wstoken=' . $token . '&wsfunction=' . $function_name;
$server_url = 'localhost/moodle/my' . '/webservice/rest/server.php'. '?wstoken=' . '15bd45a3dab2958b7e8fc237b14f76cd' .'&wsfunction='. $functionName;
dpm($server_url);
require_once('curl.inc');
$curl = new curl;
$rest_format = ($rest_format == 'json') ? '&moodlewsrestformat=' . $rest_format : '';
$resp =$curl($server_url . $rest_format, $params); //This is my line no 78
dpm($rest_format);
$respRc = json_decode($resp, true);
dpm($resp);
echo '</br>************************** Server Response createUser()**************************</br></br>';
echo $server_url . '</br></br>';
var_dump($resp);
}
Line 78 replace $curl(...) with new curl(..), your object instancing is incorrect. What is telling the php log is that you are using a variable as function name aka $curl (nothing to do with $functionName wich might have generated an error later with curl not on compile if it was wrong).
$resp = new curl($server_url . $rest_format, $params);
When I am testing my SOAP sever, I am getting the PHP warning html message with success response.
The SOAP server is like below:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
ini_set("allow_url_fopen", "On");
$server = new SoapServer("../billerwebservice/BillerWS.wsdl"); // WSDL file for function definitions
$server->setClass("Payment");
//$server->addFunction(array("payAccount","confirmRequest","voidRequest")); // Same func name as in our WSDL XML, and below
$server->handle();
class payAccountResponse {
public $return;
}
class confirmResponse {
public $return;
}
class voidResponse {
public $return;
}
class Payment extends CI_Controller {
/*function __construct(){
parent::__construct();
$this->load->library("nusoap");
}*/
public function index(){
//url for this page is base_url('api/payment')
//http://tuition24.net/admin/api/payment
//this file is in tuition24 server => /admin/application/controllers/api/Payment.php
//ini_set('display_errors', 0);
/*$l_oServer = new soap_server();
// wsdl generation
$l_oServer->debug_flag=false;
$l_oServer->configureWSDL('BillerWS', 'http://billerwebservice.co.za');
$l_oServer->wsdl->schemaTargetNamespace = 'http://billerwebservice.co.za';
// add complex type
$l_oServer->wsdl->addComplexType(
'userData',
'complexType',
'struct',
'all',
''
);
// register method
$l_oServer->register('payAccount', array(
'login' => 'xsd:string',
'password'=>'xsd:string',
'verifyOnly'=>'xsd:boolean',
'amount'=>'xsd:string',
'transid'=>'xsd:string'
),
array('return'=>'tns:userData'),
'http://billerwebservice.co.za');*/
// pass incoming (posted) data
//$l_oServer->service(file_get_contents('php://input'));
}
public function payAccount ($parameters){
/*if($verifyOnly){
if($this->checklogin($login,$password)){
return $this->enquiry($username);
}else{
}
}else{*/
$return_array = new ArrayObject();
$parameters = get_object_vars($parameters); // Pull parameters from SOAP connection
// Sort out the parameters and grab their data
$loginId = $parameters['LoginID'];
$pwd = $parameters['Password'];
$paymentRefNumber = $parameters['PayRefNo'];
$amountDue = $parameters['AmountDue'];
$code = $this->generatecode($paymentRefNumber,$amountDue);
if($this->checklogin($loginId,$pwd)){
$params = new StdClass();
$params->RespCode = '200';
$params->RespDesc = 'Success';
$params->Code = $code;
$params->PayRefNo = $paymentRefNumber;
$currentDateTime = date("y-m-d h:i:s");
//update database
$this->db->insert('payment_transactions',array(
'datetime'=>$currentDateTime,
'transactionid'=>$paymentRefNumber,
'tokennumber'=>$code,
'status'=>'Success',
'amount'=>$amountDue
));
$response = new payAccountResponse();
$response->return = $params;
return $response;
}else{
}
//}
}
public function confirmRequest($parameters){
$return_array = new ArrayObject();
$parameters = get_object_vars($parameters); // Pull parameters from SOAP connection
// Sort out the parameters and grab their data
$loginId = $parameters['LoginID'];
$pwd = $parameters['Password'];
$paymentRefNumber = $parameters['PayRefNo'];
if($this->checklogin($loginId,$pwd)){
$params = new StdClass();
$params->messageCode = '200';
$params->messageDescription = 'ConfirmOK';
$currentDateTime = date("y-m-d h:i:s");
$data = $this->db->query("select * from payment_transactions where transactionid='$paymentRefNumber'")->row_array();
$tokennumber = $data['tokennumber'];
$this->db->insert('payment_transactions',array(
'datetime'=>$currentDateTime,
'transactionid'=>$paymentRefNumber,
'tokennumber'=>$tokennumber,
'status'=>'ConfirmOK',
'amount'=>$data['amount'],
));
//$this->confirm($paymentRefNumber,$tokennumber,$loginId);
$response = new confirmResponse();
$response->return = $params;
return $response;
}else{
}
}
public function voidRequest($parameters){
$return_array = new ArrayObject();
$parameters = get_object_vars($parameters); // Pull parameters from SOAP connection
// Sort out the parameters and grab their data
$loginId = $parameters['LoginID'];
$pwd = $parameters['Password'];
$paymentRefNumber = $parameters['PayRefNo'];
$currentDateTime = date("y-m-d h:i:s");
$params = new StdClass();
$params->messageCode = '200';
$params->messageDescription = 'VoidOK';
$data = $this->db->query("select * from payment_transactions where transactionid='$paymentRefNumber'")->row_array();
$this->db->insert('payment_transactions',array(
'datetime'=>$currentDateTime,
'transactionid'=>$paymentRefNumber,
'tokennumber'=>$data['tokennumber'],
'status'=>'VoidOK',
'amount'=>$data['amount'],
));
$this->cancel($paymentRefNumber);
$response = new voidResponse();
$response->return = $params;
return $response;
}
private function checklogin($username,$password){
$data = $this->db->query("select * from payment_user where username='$username' and password='$password'")->row_array();
if($data)
return true;
else
return false;
}
private function enquiry($username){
$data = $this->db->query("select balance from user where username='$username'")->row_array();
if($data)
return $data['balance'];
}
private function generatecode($transid,$amount){
$r = rand(100000000000,999999999999);
if(!$this->db->insert('code',array('code_no'=>$r,'amount'=>$amount,'transaction_id'=>$transid))){
return $this->generatecode($transid,$amount);
}
return $r;
}
private function cancel($transid){
$this->db->delete('code',array('transaction_id'=>$transid));
}
private function confirm($transid,$card_code,$username){
$data = $this->db->get_where('code',array('code_no'=>$card_code,'transaction_id'=>$transid,'active'=>1))->row_array();
if(!$data)
return false;
$card_amount = $data['amount'];
$user_id = $this->db->get_where('user',array('username'=>$username))->row_array()['id'];
$this->db->query("UPDATE user SET balance=balance+$card_amount where username='$username'");
$this->db->insert('transaction',array(
'user_id'=>$user_id,
'reason'=>'Credited '.$card_amount.' using #'.$card_code,
'type'=>3,
'amount'=>$card_amount,
'params'=>$card_code.' '.$transid
));
$this->db->update('code',array('active'=>0),array('code_no'=>$card_code));
$bal = $this->db->get_where('user',array('id'=>$user_id))->result()[0]->balance;
return $bal;
}
}
Please let me know why I am getting these warnings.
The image attached has error shown
This is my code
class WcfClient {
public $wcfClient = null;
public $user = null;
public function __construct(){
if(isset($_SESSION['APIClient']) && $_SESSION['APIClient'] != null){
$this->wcfClient = $_SESSION['APIClient'];
}
}
public function __destruct(){
}
// Authanticate
private function Authenticate(){
global $_sogh_soapUrl, $_isDebug, $_sogh_header;
$wcargs = array();
$consumerAuthTicket = null;
if($this->wcfClient == null){
$args = array(
'clubname'=>'Wellness Institute at Seven Oaks',
'consumerName'=>'api',
'consumerPassword'=>'api'
);
try{
$wcargs = array(
'soap_version'=>SOAP_1_2
);
if($_isDebug){
$wcargs = array(
'soap_version'=>SOAP_1_2,
'proxy_host'=>"192.168.0.1",
'proxy_port'=>8080
);
}
// Connect to the API with soapclient
$soapAPIClient = new SoapClient($_sogh_soapUrl, $wcargs);
$response = $soapAPIClient->AuthenticateClubConsumer($args);
if(isset($response->AuthenticateClubConsumerResult)){
if(isset($response->AuthenticateClubConsumerResult->IsException) && $response->AuthenticateClubConsumerResult->IsException == true){
// some error occur
$this->wcfClient = null;
$_SESSION['APIClient'] = $this->wcfClient;
} else{
// set consumer ticket
$consumerAuthTicket = $response->AuthenticateClubConsumerResult->Value->AuthTicket;
// $loginData = $responseCode->ReturnValueOfConsumerLoginData;
$headers = array();
$headers[] = new SoapHeader($_sogh_header, "ConsumerAuthTicket", $consumerAuthTicket);
$soapAPIClient->__setSoapHeaders($headers);
// add to session
$this->wcfClient = $soapAPIClient;
$_SESSION['APIClient'] = $this->wcfClient;
}
}
} catch(SoapFault $fault){
$this->error('Fault: ' . $fault->faultcode . ' - ' . $fault->faultstring);
} catch(Exception $e){
$this->error('Error: ' . $e->getMessage());
}
}
return $this->wcfClient;
}
I store the soap client object in $_SESSION['APIClient'], but second times when run some data has been changed in session, I am use this class in drupal 7, I want to save the time using session, because authenticating takes long time.
Please help
Thank in advance
So I created a Spreadsheet class that is a combination of a few solutions I found online for accessing Google Sheets API with PHP. It works.
class Spreadsheet {
private $token;
private $spreadsheet;
private $worksheet;
private $spreadsheetid;
private $worksheetid;
private $client_id = '<client id>';
private $service_account_name = '<service_account>'; // email address
private $key_file_location = 'key.p12'; //key.p12
private $client;
private $service;
public function __construct() {
$this->client = new Google_Client();
$this->client->setApplicationName("Sheets API Testing");
$this->service = new Google_Service_Drive($this->client);
$this->authenticate();
}
public function authenticate()
{
if (isset($_SESSION['service_token'])) {
$this->client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($this->key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$this->service_account_name,
array('https://www.googleapis.com/auth/drive', 'https://spreadsheets.google.com/feeds'), $key
);
$this->client->setAssertionCredentials($cred);
if ($this->client->getAuth()->isAccessTokenExpired()) {
$this->client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $this->client->getAccessToken();
// Get access token for spreadsheets API calls
$resultArray = json_decode($_SESSION['service_token']);
$this->token = $resultArray->access_token;
}
public function setSpreadsheet($title) {
$this->spreadsheet = $title;
return $this;
}
public function setSpreadsheetId($id) {
$this->spreadsheetid = $id;
return $this;
}
public function setWorksheet($title) {
$this->worksheet = $title;
return $this;
}
public function insert() {
if (!empty($this->token)) {
$url = $this->getPostUrl();
} else {
echo "Authentication Failed";
}
}
public function add($data) {
if(!empty($this->token)) {
$url = $this->getPostUrl();
if(!empty($url)) {
$columnIDs = $this->getColumnIDs();
if($columnIDs) {
$fields = '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended">';
foreach($data as $key => $value) {
$key = $this->formatColumnID($key);
if(in_array($key, $columnIDs)) {
$fields .= "<gsx:$key><![CDATA[$value]]></gsx:$key>";
}
}
$fields .= '</entry>';
$headers = [
"Authorization" => "Bearer $this->token",
'Content-Type' => 'application/atom+xml'
];
$method = 'POST';
$req = new Google_Http_Request($url, $method, $headers, $fields);
$curl = new Google_IO_Curl($this->client);
$results = $curl->executeRequest($req);
var_dump($results);
}
}
}
}
private function getColumnIDs() {
$url = "https://spreadsheets.google.com/feeds/cells/" . $this->spreadsheetid . "/" . $this->worksheetid . "/private/full?max-row=1";
$headers = array(
"Authorization" => "Bearer $this->token",
"GData-Version: 3.0"
);
$method = "GET";
$req = new Google_Http_Request($url, $method, $headers);
$curl = new Google_IO_Curl($this->client);
$results = $curl->executeRequest($req);
if($results[2] == 200) {
$columnIDs = array();
$xml = simplexml_load_string($results[0]);
if($xml->entry) {
$columnSize = sizeof($xml->entry);
for($c = 0; $c < $columnSize; ++$c) {
$columnIDs[] = $this->formatColumnID($xml->entry[$c]->content);
}
}
return $columnIDs;
}
return "";
}
private function getPostUrl() {
if (empty($this->spreadsheetid)){
#find the id based on the spreadsheet name
$url = "https://spreadsheets.google.com/feeds/spreadsheets/private/full?title=" . urlencode($this->spreadsheet);
$method = 'GET';
$headers = ["Authorization" => "Bearer $this->token"];
$req = new Google_Http_Request($url, $method, $headers);
$curl = new Google_IO_Curl($this->client);
$results = $curl->executeRequest($req);
if($results[2] == 200) {
$spreadsheetXml = simplexml_load_string($results[0]);
if($spreadsheetXml->entry) {
$this->spreadsheetid = basename(trim($spreadsheetXml->entry[0]->id));
$url = "https://spreadsheets.google.com/feeds/worksheets/" . $this->spreadsheetid . "/private/full";
if(!empty($this->worksheet)) {
$url .= "?title=" . $this->worksheet;
}
$req = new Google_Http_Request($url, $method, $headers);
$response = $curl->executeRequest($req);
if($response[2] == 200) {
$worksheetXml = simplexml_load_string($response[0]);
if($worksheetXml->entry) {
$this->worksheetid = basename(trim($worksheetXml->entry[0]->id));
}
}
}
}
}
if(!empty($this->spreadsheetid) && !empty($this->worksheetid)) {
return "https://spreadsheets.google.com/feeds/list/" . $this->spreadsheetid . "/" . $this->worksheetid . "/private/full";
}
return "";
}
private function formatColumnID($val) {
return preg_replace("/[^a-zA-Z0-9.-]/", "", strtolower($val));
}
}
I then use this test php file to add rows to to my spreadsheet:
$Spreadsheet = new Spreadsheet();
$Spreadsheet->
setSpreadsheet("test spreadsheet")->
setWorksheet("Sheet1")->
add(array("name" => "Cell 1", "email" => "Cell 2"));
With this I can delete a row / update a row and append a row. However, the MAIN reason I needed this was to INSERT a row. Has anyone figured out a way to do this? Any language is fine although id prefer a php solution.
You can call an Apps Script stand alone script from PHP using an HTTPS GET or POST request. PHP can make a GET or POST request, and Apps Script can obviously insert the row anywhere using SpreadsheetApp service. You'll probably want to use Content Service also inside of the Apps Script code to get a return confirmation back that the code completed.
You might want to use a POST request for better security. So, again, you can use Apps Script as an intermediary between your PHP and your spreadsheet. The doPost() in the Apps Script file will need an event handler, normally assigned to the letter "e":
doPost(e) {
//Get e and retrieve what the code should do
//Insert the row
};
Also, see this answer:
Stackoverflow - Call a custom GAS function from external URL