Microsoft Graph api cannot send invitation to share document - php

My goal is to share a document/file with another user.
I am using https://learn.microsoft.com/en-us/graph/api/driveitem-invite?view=graph-rest-1.0&tabs=http to do it.
Error I have:
Client error: POST https://graph.microsoft.com/v1.0/me/drive/root:/operations.xlsx:/invite resulted in a 400 Bad Request response: {"error":{"code":"BadRequest","message":"The request is malformed or incorrect. Expected array for value of property: Collection(microsoft.graph.driveRecipient)","innerError":{"date":"2022-03-08T10:48:30","request-id":"xxx-xxxx-xxxxx","client-request-id":"xxx-xxxx-xxxxx"}}}
Find below my code:
operations.xlsx is the file I am trying to share.
public function send(){
$viewData = $this->loadViewData();
$graphs = $this->getGraph();
$body = array(
"requireSignIn"=> true,
"sendInvitation" => true ,
"roles" => "[write | read]",
"recipients"=>array(
"email"=> "person#email.com"
),
"message"=> "Here is the file."
);
$graphs->createRequest("post", "/me/drive/root:/operations.xlsx:/invite")
->attachBody($body)
->execute();
return response()->json($graphs);
}
I am using Laravel for the project.

public function sended(){
$viewData = $this->loadViewData();
$graphs = $this->getGraph();
$body = array(
"requireSignIn"=> true,
"sendInvitation" => true ,
"roles" => ["read"],
"recipients"=>array([
"email"=> "person#email.com"
]),
"message"=> "Here is the file."
);
$graphs->createRequest("post", "/me/drive/root:/operations.xlsx:/invite")
->attachBody($body)
->execute();
return response()->json($graphs);
}

Related

Insert multiple json data into mysql database from postman using codeigniter api

I am tring to insert multiple data in db using postman but only single data is insetred successfully ,when inserting multiple data getting 500 error.Please help me on how can i insert multiple data in db.Any help would be highly appreciated.Thank you.
PostMan raw data:
[{
"total_sales":"14",
"total_product":"21",
"total_profit":"5099",
"total_distributor":14,
"total_ratail":40 },
{
"total_sales":14,
"total_product":21,
"total_profit":50,
"total_distributors":14,
"total_ratail":40 }
]
Below is my code:
public function create()
{
$model = new AdminModel();
print_r("total_sales");
$data = array(
'total_sales'=>$this->request->getVar('total_sales'),
'total_product'=>$this->request->getVar('total_product'),
'total_profit'=>$this->request->getVar('total_profit'),
'total_distributors'=>$this->request->getVar('total_distributors'),
'total_ratail'=>$this->request->getVar('total_ratail'),
);
$query = $model->where('id', $data['total_sales'])->find();
if(count($query)>0){
$model->update->where('id', $data['total_sales'])->find();
}
else{
$model->insert($data);
}
//$model->insert($data);
$response = [
'status' => 200,
'error' => null,
'messages' => [
'success' => 'Data Saved'
]
];
return $this->respondCreated($response);
}
You are adding an array of objects but the code is expecting only one object. That's why you are getting the error.
You have to modify your php code to accept an array and loop through them.

How can I add the filter so that API call is returning just the results that I want?

This is what I got so far, but it doesn't work.
public function getCompleteness(){
$searchBuilder = new AkeneoSearchBuilder();
$searchBuilder->addFilter('completeness', '=', 100);
try {
$products = $this->apiClient->getProductApi()->all(
50,
[
'search' => $searchBuilder->getFilters(),
'scope' => 'ecommerce'
]
);
} catch (HttpException $e){
echo "Message: " . $e->getMessage();
echo "Code: " . $e->getCode();
}
return $products;
}
}
This is the call that I am trying to use from Akeneo API.
{{url}}/api/rest/v1/products?search={"completeness":[{"operator":"=","value":100,"scope":"ecommerce"}]}
How can I use GetCompleteness() method in order that it produces some results ? I have problem with using AkeneoSearchBuilder();
When you do:
$searchBuilder = new AkeneoSearchBuilder();
$searchBuilder->addFilter('completeness', '=', 100);
$products = $this->apiClient->getProductApi()->all(
50,
[
'search' => $searchBuilder->getFilters(),
'scope' => 'ecommerce'
]
);
It basically means: "For all products complete on scope "undefined", give me all their "ecommerce" values".
What you are trying to achieve is (I guess): "For all products complete on scope "ecommerce", give me all their values".
As you can read on the official documentation about completeness filter, you need to specify a scope:
$searchBuilder = new AkeneoSearchBuilder();
$searchBuilder->addFilter('completeness', '=', 100, ['scope' => 'ecommerce']);
Now you can retrieve their values, by calling:
$products = $this->apiClient->getProductApi()->all(
50,
[
'search' => $searchBuilder->getFilters()
]
);
Note that I removed the "scope" parameter here.
To resume:
You need to specify a scope when filtering by completeness
The scope parameter on the query is to retrieve only values of this scope

Codeigniter Rest API : Put request doesn't get passed id

I developed a REST API using REST Library for Phil Sturgeon,
GET and POST requests working fine ,
Now when I try to access the passed params with PUT request, I get null.
class ApiItems extends REST_Controller
{
function __construct() {
//
}
public function items_get(){ // //}
public function items_post(){ // //}
public function items_put()
{
if(!$this->put('id')) //My issue : I can't get the id here
{
$this->response(array('error' => 'Item id is required'), 400);
}
$data = array(
'id' => $this->put('id'),
'code'=> $this->put('code'),
'name' => $this->put('name'),
'quantity' => $this->put('quantity')
);
$this->item_model->update_item($this->put('id'), $data);
$message = array('success' => $id.' Updated!');
$this->response($message, 200);
}
}
I tested it using POSTMAN and I get this :
POSTMAN PUT Call screenshot
I dont understand why $this->get(id) or $this->post(id) are working fine,and not the case for $this->put(id) ?
It's working ,I ve done a stupid mistake when filling the parameters with POSTMAN, I checked form-data instead of x-www-form-url-encoded

How to insert an object into MongoDB document using Laravel 4

I am a newbie in Laravel MongoDB I would like to mention a problem here, outline of my Mongo document should be like
{
_id:****,
subscriptions: [{list_id: "14Q3"},
{list_id: "153"}],
offers: [ { targetURL: "www.qwerty.com", title: "25% discount" },
{ targetURL: "www.abcd.com", title: "55% discount" } ],
}
I have used the following code to insert a list id (was successful).
DB::connection('mongodb')->collection('subscribers')->insert(array(
'_id' => $subscriber->device_id,
'subscriptions' => array('list_id' => $subscriber->list1_id),
));
But when I try to push another list_id as next object it is showing error. I used the following code for pushing
DB::connection('mongodb')->collection('subscribers')
->push('subscriptions', array('list_id' => $subscriber->list1_id));
I don't know whether my code is right or wrong. I need to store the data as the outline given above. This is My actual problem. Please correct me....
My controller is is given below, I create new collection for each subscriber. Problem is second 'if' statement
public function store() {
$newsubscriber = Input::json();
//DB::connection('mongodb')->collection($newsubscriber->get('device_id'))->delete();
$result = Subscriber::where('list1_id',$newsubscriber->get('list_id'))->where('device_id',$newsubscriber->get('device_id'))->get();
if (!$result->isEmpty()) {
return "You are already a subscriber of this List";
}
else{
$result1 = Subscriber::where('device_id',$newsubscriber->get('device_id'))->get();
$subscriber = new Subscriber();
$subscriber->list1_id = $newsubscriber->get('list_id');
$subscriber->device_id = $newsubscriber->get('device_id');
$subscriber->subtype = 1;
$subscriber->save();
if (!$result1->isEmpty()) {
DB::connection('mongodb')->collection($subscriber->device_id)->push('subscriptions', array('list_id' => $subscriber->list1_id));
return "Subscribed successfully 1";
}
else{
DB::connection('mongodb')->collection($subscriber->device_id)->insert(array('_id' => $subscriber->device_id,'subscriptions' => array('list_id' => $subscriber->list1_id),
));
return "Subscribed successfully 2";
}
}
}
First i have used following API
curl -H "Content-Type: application/json" -d '{"list_id":"2","device_id":"987654321"}' http://localhost/lemmeknw/public/index.php/api/v1/subscribe
This returned "Subscribed successfully 2"
but when I used API for second time
curl -H "Content-Type: application/json" -d '{"list_id":"1","device_id":"987654321"}' http://localhost/lemmeknw/public/index.php/api/v1/subscribe
There was error "Something went wrong"
I don't know much about Laravel, but what I'm seeing here:
DB::connection('mongodb')->collection('subscribers')->insert(array(
'_id' => $subscriber->device_id,
'subscriptions' => array('list_id' => $subscriber->list1_id),
));
Looks like you are creating subscriptions as an object {list_id: <subscriber-list1_id>} instead of an array of one object [{list_id: <subscriber-list1_id>}]. So when you try to use the push operation
DB::connection('mongodb')->collection('subscribers')
->push('subscriptions', array('list_id' => $subscriber->list1_id));
that is an attempt to push to an object, not an array. My guess is that you will need to modify your insert to be
DB::connection('mongodb')->collection('subscribers')->insert(array(
'_id' => $subscriber->device_id,
'subscriptions' => array(array('list_id' => $subscriber->list1_id)),
));

What is AuthComponent::getModel() alternative in cakePHP2x?

I am using a Remember Me Component. Actually, migrating a CakePHP 1.3 app to CakePHP 2x. I am stuck with this LAST PIECE of code that is RememberMeComponent.
The script which I see here to SET the cookie is :
function make( ) {
$data = array(
$this->ident_field => $this->_create_token( ),
$this->token_field => $this->_create_token( ),
);
$this->Cookie->name = $this->cookie_name;
$this->Cookie->time = $this->period;
$this->Cookie->key = base64url_encode(implode('::', $data));
$this->Cookie->secure = true;
$this->Auth->getModel()->save(array($this->Auth->userModel => array_merge(array('id' => $this->Auth->user('id')), $data)), false);
}
and checks with :
function check( ) {
$cookie = $this->Cookie->read($this->cookie_name);
if (empty($cookie)) {
return false;
}
$data = explode('::', base64url_decode($cookie));
$user = $this->Auth->getModel( )->find('first', array(
'conditions' => array(
$this->Auth->userModel.'.ident' => $data[0],
),
));
if ( ! $user) {
return false;
}
function base64url_encode is defined in bootstrap - so, it is valid function.
Now there is line:
$this->Auth->getModel()->save(array($this->Auth->userModel => array_merge(array('id' => $this->Auth->user('id')), $data)), false);
That is giving me an error:
Error: Call to undefined method AuthComponent::getModel()
File: /var/www/FlintStones/Controller/Component/RememberMeComponent.php
I checked Auth Component documentation but, it did not have any option where I could find the model for auth.
Thanks in advance.
PS: We cannot directly move to Auto Login (as you might have that in mind) or if you can also refer to a quick-step-by-step, please share. I might even consider that but, so far it is just to get the Auth model.
I had the same issue in the same component.
How to get $settings data out of CakePHP 2.0 FormAuthenticate object
Summary:
Use $this->Auth->userModel to get the model. If the value is null, it will default to 'User'.

Categories