Author Topic: how to save to database via api  (Read 739 times)

Offline shera85

  • Newbie
  • *
  • Posts: 1
  • Karma: +1/-0
    • View Profile
how to save to database via api
« on: March 15, 2019, 11:13:46 PM »
Hi,

I want to extend api to insert into db but for some reason it's returning empty 200 message all the time. Even I'm trying to pass static response it's still giving 200 with empty response.

class ControllerApiAccountDriverLocationCreate extends AControllerAPI
{
    public $data;

    public function post()
    {
       
        $this->extensions->hk_InitData($this, __FUNCTION__);
       
        $request_data = $this->rest->getRequestParams();

        $order_id = $request_data["order_id"];
        $driver_id = $request_data["driver_id"];
        $lat = $request_data["latitude"];
        $long = $request_data["longitude"];

        if ($this->customer->isLoggedWithToken($request['token'])) {
            $this->rest->setResponseData(array('error' => 'Already Logged in. Can not create new account.'));
            $this->rest->sendResponse(401);
            return null;
        }

        $this->loadModel('account/customer');
        $this->loadLanguage('account/driverlocation');
             
        $result = $this->model_account_customer->saveDriverLocation($order_id, $driver_id, $lat, $long);
        $this->data["result"] = $result;

       
        $this->extensions->hk_UpdateData($this, __FUNCTION__);

        $this->rest->setResponseData($this->data);
        $this->rest->sendResponse(200);
    }

}


and model is

   public function saveDriverLocation($order_id, $driver_id, $lat, $long){


        $this->db->query("INSERT INTO `abki_driver_location`
                    SET order_id = '".(int)$order_id."',
                        driver_id = '".(int)$driver_id."',
                        latitude = '".$lat."',
                        longitude = '".$long."',
                        created_date = NOW()");

        return $this->db->getLastId();

    }


What am I doing wrong here

Thanks in advance.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1786
  • Karma: +250/-11
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: how to save to database via api
« Reply #1 on: March 18, 2019, 05:39:45 AM »
hmm.. Your code looks fine..try to debug (with logging $this->log->write(''dddd') or something like that..)
Be sure you sends post-request with token.
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline appsted

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-2
  • Hire Offshore Android App Developer From Appsted
    • View Profile
    • Android App Developer
Re: how to save to database via api
« Reply #2 on: December 18, 2019, 01:06:18 AM »
It is not difficult to save database from API, If you have faces any type of issue then you can Hire web developers and solve your all query.

 

Powered by SMFPacks Social Login Mod