Sendgrid Event notification POST data is always null - codeigniter

I have added a url to get the POST response from Sendgrid for event notification
code to capture result is like
$result = file_get_contents('php://input');
$events = json_decode($result, true);
$this->db->insert('delivery_temp', ['response' => $events]);
I am always getting the result as NULL when I try by hitting Test your integration button in sendgrid.
The above code is added in index function of a controller in codeigniter.
url is like http://testing.site_name.com/email_status
Thanks in advance

Related

Laravel GET Method not sending raw JSON in Server

Working with REST API's in Laravel. Can't send raw json request in body using GET method, it returns null values in my server environment. But in local server works fine. Refer the attached images. And my controller code was,
public function slots(Request $request)
{ //return $request->all();
$consult_rule = TRUE;
date_default_timezone_set('Asia/kolkata');
$current_time = date('H:i:s');
$curr_date = date('Y-m-d');
// $appoint_date = DateTime::createFromFormat('d/m/Y', $request->appoint_date)->format('Y-m-d');
// $appoint_date_format = strtotime($appoint_date);
// $appoint_day = date('l', $appoint_date_format);
$date = $request->appoint_date;
$doctor_id = $request->doctor_id;
$appoint_for = $request->appoint_for;
return $this->sendResponse(['doctor_id' => $doctor_id,'appoint_date' => $date,'appoint_for' => $appoint_for], 'Data retrieved successfully.');
}
And the images,
For Local server works fine
Localhost response
For Server works fine with Key Parameters
Server response with key parameters
For Server return null values with raw JSON parameters
response with raw JSON parameters
Since it is a GET route, it expects parameters in URL.
For POST request, you need to define a separate Route and function which will take parameters in body.
EDIT: you can't send parameters in body when using GET HTTP method.
Refer:
https://laravel.com/docs/7.x/routing#required-parameters

To create restful api for android team in Laravel 5.2

I am currently creating Rest API for Android Team using Laravel 5.2 and testing the API in RESTCLIENT.
I am just trying to get the form values which are entered in Restclient with POST method.
I have problem with POST method.. I m just not able to get the form field values. My API for GET method works fine.
Kindly guide me.
Thanks
This is how you handle POST request in laravel. Be it 5.2 or 5.4.
Route::post('books', 'BookController#store');
Controller
pubic function store(Request $request)
{
$name = $request->name;
$name = $request->get('name');
$name = request('name'); //global helper
//Your testing with api so you should return to api if you want to see it
return response()->json($name);
}
Then check in Android console if you receive $name in JSON format.

Laravel 5.1 | VueJs request randomly returns a login request

Im working on a project using vuejs and laravel 5.1 but i have a major problem. When i add data to the database using this code through Vuejs it randomly returns with a get request to the login page and doesn't enter the data.
this.$http.post('createAccount', this.account, function (data) {
//disable the loader
$('#loader').removeClass('active');
//show the success message with the new user url
var url = 'account=' + data;
var astr ="<a href='" + url + "'>" + " Success! View The Account By Clicking Here " + "</a>";
//Display sweet alert notification
global.displaySuccess('User Created', astr);
alert(astr);
}).error(function(data, status, request) {
global.displayError(status, 'Something went wrong!',
'Please make sure that all the fields are filled out!');
});
The above code works just fine about 3 times before it sends a request to go back to the login page as shown below.
And also when this happens sweet alert returns an extra 2 characters at the beginning of where the link should be. (Below Image)
If you reference back to the code, note the alert(astr), this is just to see whats being returned by the data. Every time the login request is randomly added this alerts the HTML code for the login page.
Lastly just incase anyone is curious this is route that its being posted to along with the code that its accessing in the controller.
//routes.php
Route::group(['prefix' => 'profitloss', 'middleware' => 'perm'], function(){
post('createAccount', 'AccountController#create');
});
//AccountController#create
public function create(Request $request)
{
$account = new Account();
$account->account_username = $request->input('account_username');
$account->account_password = $request->input('account_password');
$account->email_address = $request->input('email_address');
$account->email_password = $request->input('email_password');
$account->notes = $request->input('notes');
$account->gender = $request->input('gender');
$account->display_name = $request->input('display_name');
$account->first_name = $request->input('first_name');
$account->last_name = $request->input('last_name');
$account->save();
//return the id of that account.
return $account->id;
}
NOTE: I've had to disable CSRF because for some reason it keeps failing validation half the time and working the other half, However I don't think that this has anything to do with it.
Any help or information from anyone who has had a similar error to this would be greatly appreciated, thank you!

Symfony2 + AJAX: Can't fetch data in controller

Problem
I'm using Symfony2 with AJAX to insert a new record in my 'locations' table.
I can easily pass the data I want from the form to my Controller that handles that
AJAX request. I checked with Firebug and all the GET values are as I wanted.
Just to be clear the controller is not in the location controller but in the debug controller, don't know if that matters. (just for sandbox-testing atm).
Because of the relationships in the database the location entity has a district column which needs a district-entity object.
Problem is now this code is returning the succes response fine if I leave out the $em->flush(). If I add the $em->flush() to perform the insert, I get an 500 Internal error in my console of my browser.
Here's the code for my controller:
$request = $this->container->get('request');
if($request->isXmlHttpRequest()){
$street = $request->query->get('street');
$zip = $request->query->get('zip');
$lat = $request->query->get('lat');
$name = $request->query->get('name');
$number = $request->query->get('number');
// insert into object
$entity = new Location();
$entity->setStreet($street);
$entity->setZip($zip);
$entity->setLat($lat);
$entity->setName($name);
$entity->setNumber($number);
$em = $this->getDoctrine()->getManager();
$district = new District();
// get the district hard coded for testing
$district = $em->getRepository("SnowFrontBundle:District")->find(7);
$entity->setDistrict($district);
//$entity->setDistrict(null);
$em->persist($entity);
$em->flush();
//prepare the response, e.g.
$response = array("code" => 100, "success" => true);
return new Response(json_encode($response));
}
Question
What could be wrong with the $em->flush() part? How can I see what the real error is? (instead of 500 internal error). As well should I be using a createFormBuilder?

XmlHttpRequest in Symfony2

Here follows my problem. In a Symfony2.1 controller I receive an Ajax call. If I use the Request object I'm not able to get the sent param. If I use the PHP _REQUEST object the param is found!
I can confirm that the request is XHR, if it matters.
Here is my code:
public function savedataAction(Request $request){
if($request->isXmlHttpRequest())
echo 'Ajax Call';
$param1 = $request->request->get('myParam'); // Nothing is returned, but $request is obviosly not null
$param2 = $_REQUEST['myParam']; // The value is given
....
}
Any idea?
PS: If helps, notice that the AJAX call is sent by the file uploader jQuery plugin provided by Valums.
Normally its:
// retrieve GET and POST variables respectively
$request->query->get('foo');
$request->request->get('bar', 'default value if bar does not exist');
Look here are the fundamentels.
http://symfony.com/doc/current/book/http_fundamentals.html
Edit:
$request in your case is only filled when you send the form from the Symfony2 site. It is possible, that the CSRF protection block the request.
Try this in your controller to get the Request object:
$request = $this->get('request');
http://symfony2forum.org/threads/5-Using-Symfony2-jQuery-and-Ajax

Resources