ODOO Web Service sending php form to the odoo - odoo-10

i need to send request to my url using php to odoo 10 to specific model and i got an error: Call to a member function scalarval() on integer
please any one knows about can help me at fast time
<?php
include("xmlrpc.inc");
$user = "Ammar";
$password = "1235";
$db = "Test";
$serverUri = "http://localhost:8080/";
$client = new xmlrpc_client($serverUri . 'common');
$msg = new xmlrpcmsg('login');
$msg->addParam(new xmlrpcval('9_xmlrpc', "string"));
$msg->addParam(new xmlrpcval('admin', "string"));
$msg->addParam(new xmlrpcval('admin', "string"));
$res = $client->send($msg);
$val = $res->value();
$id = $val->scalarval();
$create_feedback_form = array(
'name' =>new xmlrpcval($_POST['name'],'string'),
'description' =>new xmlrpcval($_POST['description'],'string'),
'phone' =>new xmlrpcval($_POST['phone'],'string'),
);
$client = new xmlrpc_client($serverUri . 'object');
$msg = new xmlrpcmsg('execute');
$msg->addParam(new xmlrpcval('9_xmlrpc', "string"));
$msg->addParam(new xmlrpcval('1', "int"));
$msg->addParam(new xmlrpcval('admin', "string"));
$msg->addParam(new xmlrpcval("feedback.form", "string"));
$msg->addParam(new xmlrpcval("create", "string"));
$msg->addParam(new xmlrpcval($create_feedback_form, "struct"));
$res = $client->send($msg);
if($res){
echo 'Successfully Submited'; exit;
}
?>

You should try using a more friendly and supported php xmlrpc library like ripcord, you will find a lot of more help and examples like the ones at:
https://www.odoo.com/documentation/11.0/webservices/odoo.html

Related

How to attach file with api request in laravel store controller?

Here is my controller
I would like to attach a file that was requested from Postman API, please help me to solve my problem.
$p = new PersonAskPermission();
$p->start = $request->start;
$p->end = $request->end;
$p->day = $request->day;
$p->person_id = $request->person_id;
$fileTemp = $request->file('file');
$fileExtension = $fileTemp->getClientOriginalExtension();
$fileName = Str::random(4). '.'. $fileExtension;
$path = $fileTemp->storeAs(
'apiDocs', $fileName
);
$p->getTypes()->attach($p_type);
$p->getReasons()->attach($p_reason);
return response()->json([
'message' => 'Permission Reason created successfully!',
'data' => $p
]);
}

image not store in database laravel

I want to Create app in laravel that manage my events
i use this code for EventController
public function store(Request $request)
{
$request->validate([
'inviter'=>'max:255',
'date'=>'max:255',
'phone'=>'max:255',
'whatsapp'=>'max:255',
'location'=>'max:255',
'approval'=>'max:255',
'number'=>'max:255',
'description'=>'max:255',
'track'=>'max:255',
]);
$eve = new Event([
'inviter'=> $request->get('inviter'),
'date'=> $request->get('date'),
'phone'=> $request->get('phone'),
'whatsapp'=> $request->get('whatsapp'),
'location'=> $request->get('location'),
'number'=> $request->get('number'),
'approval'=> $request->get('approval'),
'description'=> $request->get('description'),
'track'=> $request->get('track'),
]);
if ($request->hasFile('file')) {
$file = $request->file('file');
$fileName = $file->getClientOriginalName();
$filePath = time() . '.' . $file->getClientOriginalName();
$request->file->move(public_path('uploads/events'), $filePath);
$eventImage = Image::createNew();
$eventImage->filename_path = $filePath;
$eventImage->original_filename = $fileName;
$eventImage->event_id = $eve->id;
$eventImage->save();
}
return redirect(route('event.index'))->with('success','Event Created');
}
but image dont create I think related to event_id when I was testing the code correctly and incorrectly
Try this
$eve = Event::create([
'inviter'=> $request->get('inviter'),
'date'=> $request->get('date'),
'phone'=> $request->get('phone'),
'whatsapp'=> $request->get('whatsapp'),
'location'=> $request->get('location'),
'number'=> $request->get('number'),
'approval'=> $request->get('approval'),
'description'=> $request->get('description'),
'track'=> $request->get('track'),
]);

Sending an image with HTTP POST

Recently I wanted to separate my project in different services to I wanted to make blogs independent from the project.
In the first project i have written this code. I want to send the data that i get from the form to another API http://127.0.0.1:100/api/saveBlog
public function update(Request $request, $blog)
{
if (!$blog instanceof Blog) {
$blog = $this->getById($blog);
}
$response = Http::post("http://127.0.0.1:100/api/saveBlog",[
'name' => $request->input('name'),
'description' => $request->input('description'),
'name' => $request->input('name'),
'photto' => $request->file('photto')
]);
dd($response->status());
}
In the API service i am trying to read the data
Route::post("/saveBlog",function (Request $request){
$blog = new Blog();
$blog->name = $request->input('name');
$blog->description = $request->input('description');
$blog->name = $request->input('name');
$main = $request->file('photto');
$fileName = microtime() . '.' . $main->getClientOriginalExtension();
$img = Image::make($main->getRealPath());
$img->resize(400, 400);
$img->stream();
Storage::disk('local')->put('public/blogs/' . $fileName, $img, 'public');
$blog->image_path = "/storage/blogs/" . $fileName;
return $blog->save();
});
But i am getting 500 status error and blog is not being saved in database.
I think the problem is with $request->file('photto')
ANY IDEA?
check whether image exist in request like below
if($request->has('photto')){
$main = $request->file('photto');
$fileName = microtime() . '.' . $main->getClientOriginalExtension();
$img = Image::make($main->getRealPath());
$img->resize(400, 400);
$img->stream();
Storage::disk('local')->put('public/blogs/' . $fileName, $img, 'public');
$blog->image_path = "/storage/blogs/" . $fileName;
}
Updates
$photo = fopen(public_path('/storage/filename'), 'r');
$response = Http::
attach('photo', $photo)
->post($url, [
'param_1' => 'param_1 contents',
...
]);

can't autometic sms using twilio

I can send sms when a user click on a button but i can't send sms when a user set a time or date and sms will send autometic on that times.
in the below code is when a user click on a button for sent sms. Now what thinks should i change to solved my problem.Please help me i need help.
<?php
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;
/*echo '+'.$_REQUEST['mobile'];*/
if (isset($_REQUEST['mobile'])) {
$sid = '';
$token = '';
/*$client = new Twilio\Rest\Client($sid,$token);*/
$client = new Client($sid, $token);
$message = $client->messages->create(
'+'.$_REQUEST['mobile'],
array(
'from' => '',
'body' => 'testing'
)
);
}
?>
You Have to add Country code with Plus sign Like +1 for USA and +91 for India.
require __DIR__ . '/vendor/autoload.php';
use Twilio\Rest\Client;
if (isset($_REQUEST['mobile'])) {
$sid = '';
$token = '';
$client = new Client($sid, $token);
$message = $client->messages->create(
'+{Country_Code}'.$_REQUEST['mobile'],
array(
'from' => '',
'body' => 'testing'
)
);
}

how to change laravel directory from storage/app/public to public/media

Please i want to change the default laravel configuration from storage/app/public to public/media on the server. In localhost it worked with storage:link but on the server it isn't working even after adding a symlink. Below is my symlink code.
<?php symlink('/home/cemo/cem/storage/app/public','/home/cemo/public_html');
Also if i return the public_path() from the store function i get /home/cemo/cem/public
this is the structure of my cpanel
below is my store function using image intervention
public function store(Request $request)
{
return public_path();
$this->validate($request,[
'title'=>'required|min:6',
'body'=>'required'
]);
if($request->hasFile('image')){
$img = $request->file('image');
$imgName = time().'-'.uniqid() . '.' . $img->getClientOriginalExtension();
}
else{
$imgName = 'default.jpg';
}
$posts = new post;
$posts->title = $request->title;
$posts->body = $request->body;
$posts->posted_by = $request->posted_by;
$posts->status = $request->status;
$posts->position = $request->position;
$posts->image = $imgName;
$posts->source = $request->source;
$posts->save();
$posts->tags()->sync($request->tags);
if(!empty($img)){
Image::make($img)->resize(1500,550)->save(public_path('/media/images/blog/'. $imgName));
}
$notification = array(
'message' => 'Successfully created',
'alert-type' => 'success'
);
return redirect(route('post.index'))->with($notification);
}
In config/filesystems.php
Change the array to:
'root' => 'public/media',

Resources