Add groups as collaborator - box-api

I am trying to add a group as a collaborator of a folder using the BOX.net api but i can't.
I am not having any issues to add users, but i couldn't add groups.
I am doing it as they say to do it: {id: "GROUP_ID"} but i am getting a "NOT FOUND" error.
I checked the group and folder id and they are both correct.
Did anyone face this issue before? Is there somebody who can help me with this? I would really appreciate it.
Thanks in advance,
Regards,
Marcelo

You have to be a group administrator on the Box Enterprise in order to manage groups. You may need to ask your Box admin to add you as a co-admin, and give you the "manage groups" permission.

Make sure you pass in "type":"group" in the accessible_by field in addition to "id":"GROUP_ID".
This should be documented soon.

Here's a small example of adding a group as collaborator (PHP). This is done via the V2 API, in case you're using the V1 api (saw you mentioned box.net's api, which is the V1 api).
function addGroupColaborator($folderId, $groupId, $accessType, $accessToken){
$options = array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_VERBOSE => true,
CURLOPT_HEADER => false,
CURLINFO_HEADER_OUT => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => false
);
$url = 'https://api.box.com/2.0/collaborations?notify=false';
$options[CURLOPT_HTTPHEADER] = array ("Authorization: Bearer ".$accessToken);
$postf = array(
"item" => array(
"id" => $folderId,
"type" => "folder"
),
"accessible_by" => array(
"id" => $groupId,
"type" => 'group'
),
"role" => $accessType
);
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = json_encode($postf);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result, true);
}

Related

Why not returning full value on Laravel -Guzzle

I am trying to return the JSON data from a third party API with Laravel-Guzzle. Everything is working but the value is different it's like some kind missing characters specially on images.
Here's Laravel-Guzzle code :
$client = new \GuzzleHttp\Client();
$request = $client->request('GET',
'https://targetweb.com/api/v2/search_items/?', [
'query' => [
'by' => 'relevancy',
'keyword' => 'productx',
'limit' => 50,
'newest' => 0,
'order' => 'desc',
'page_type' => 'search',
'version' => 2
]
]);
$array = json_decode($request->getBody()->getContents(), true);
$nArrItems = count($array['items']);
for ($x=0;$x<$nArrItems;$x++){
echo $array['items'][$x]['name'].'<br/>';
$nImages = count($array['items'][$x]['images']);
for($z=0;$z<$nImages;$z++){
echo $array['items'][$x]['images'][$z]."<br/>";
}
}
Result on my browser running Laravel
It has same result as with API tester
Result API tester
but if I compare it(the above) with chrome inspect
Chrome inspect
in my browser : "309adc074bfeef9ad6d13561ef2","70eb....
in API tester : "images":["309adc074bfeef9ad6d13561ef2","70eb....
in Chrome inspect : "images":["309adc074bfeef9ad6d13561ef2e3ad1","70eb....
It has missing characters that does not show in my browser & API Tester.
Any help as why this is happening would be greatly appreciated.

Is there a way to put "subject" into the function:mailto in a Datacolumn in yii2?

The problem is the following: I have an Html::mailto() in my Datacolumn where I wanna give the value of the subject with it.
I can't use swiftmailer or some other extensions because I don't want to generate an email, instead, I want to open outlook, by clicking the hyperlink, and have the subject pre-written there.
This is the function:
public static function mailto($text, $email = null, $options = [])
This is my code:
[
'class'=>'\kartik\grid\DataColumn',
'attribute' => 'email',
'label' => 'E-Mail',
'format' => 'raw',
'value' => function($model){
$email = SucheBiete::find()
->select(['email'])
->join('INNER JOIN', 'user', 'user.user_id = suche_biete.user_user_id')
->scalar();
return Html::mailto('Kontaktaufnahme mit: ' . $email,$email, ['subject' => 'Hi There']);
}
]
It works but without getting the subject:
is the $option parameter the right one to give a subject,textbody or cc?
Try to attach the subject to the second parameter:
return Html::mailto('...: ' . $email,"$email?subject=HiThere" );
Maybe you need to encode() the subject for preserving spaces.

Customize prestashop web service

I want to customize Prestashop web service for my own usage but I don't know how and I can't find any tutorial. I have a mobile application that want to retrieve data from website but the default web service is useless.
For example I want the list of categories (in a language) with they're pictures but It seems I should call two different service to retrieve categories and images separately.
Assume I want to have a JSON array of categories that a category is a JSON object that have these fields {id,title,imageUrl} but It seems I should get {id,title} with a method and after that I can get images on by one by another method!
I couldn't find any guide for extending or customizing web service in the documentation.
I'm a bit late but:
Prestashop version requier : > 1.6
If you want to customize a web service and return specific fields with a JSON format output. You need to do it this way:
First
In override :
Create a class : myClassForWs that extends myClassCore
Override WebserviceRequest in webservice/WebserviceRequest.php
In webservice/WebserviceRequest.php : Add myClassForWs to
ressources:
public static function getResources()
{
$resources = parent::getResources();
$resources['myClassForWs'] = array('description' => 'The class','class' => 'myClassForWs');
ksort($resources);
return $resources;
}
}
In myClassForWs : redefine $webserviceParameters and $definition with the fields you need:
protected $definition = array(
'table' => 'category',
'primary' => 'id_category',
'multilang' => true,
'multilang_shop' => true,
'fields' => array(
'name' =>array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 128),
'link_rewrite' =>array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isLinkRewrite', 'required' => true, 'size' => 128),
'description' =>array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
),
);
protected $webserviceParameters = array(
'objectsNodeName' =>'categories',
'hidden_fields'=>array('nleft', 'nright', 'groupBox'),
'fields' => array(
'level_depth' => array('setter' => false),
),
'associations' => array(
'images' => array(
'resource' => 'image',
'fields' => array('id' => array())
),
),
);
Then
Go in your admin tab :
in performance : clear cache
in advanced settings > Web service: active a api Key and set myClassForWs for this key
Finally
Access to your web service with url :
my.prestashop/api/myClassForWs/{id_class}?output_format=**JSON**
And it returns your datas
I hope it helps.

CakePHP basic auth on API (json) request

I want to make a request to resource/index.json, but since I index is not allowed without authentication it redirects me to login page. That's the behavior I want when no username:password has been sent
The thing is how do I set AuthComponent to work with both Form and Basic and only check for basic when the request goes through api prefix.
Also, does it automatically authenticate when found username and password in the header or do I have to do it manually?
in respective controller add few lines
class NameController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow("index");
}
}
This will allow index without authentication.
I decided to use Friend's of Cake TokenAuthenticate, and yes, it works along with FormAuthenticate so I am able to use both.
As a matter of fact, it automatically chooses the component it's going to use based on if there is an existing _token param or a X-MyApiTokenHeader header.
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form',
'Authenticate.Token' => array(
'parameter' => '_token',
'header' => 'X-MyApiTokenHeader',
'userModel' => 'User',
'scope' => array('User.active' => 1),
'fields' => array(
'username' => 'username',
'password' => 'password',
'token' => 'public_key',
),
'continue' => true
)
)
)
);

Retrieve all data from one table, and some from another in CakePHP

In my CakePHP site, I want to make a drop-down list of all Venues, and any Restaurants that have is_venue=1.
I've tried this in my events_controller:
$venueOptions = array(
'fields' => array('id', 'name_address'),
'order' => array('name'),
'join' => array(
array(
'table' => 'restaurants',
'alias' => 'Restaurants',
'type' => 'inner',
'fields' => array('id', 'name'),
'foreignKey' => false,
'conditions' => array('restaurants.is_venue = 1')
)
),
);
$venues = $this->Event->Venue->find('list', $venueOptions);
But it appears to still just be getting the venues. I don't really need an association between the two, since their associations will both be with an event, not each other.
Where have I gone wrong? Am I close, but just need to tweak this code, or am I just all-together doing it wrong?
I think you could do something along the lines of:
<?php
....
$v = $this->Venue->find( 'list' );
$r = $this->Restaurant->find( 'list' );
$venues = Set::merge( $v, $r );
natcasesort( $venues );
// print_r( $venues );
$this->set( 'venues', $venues );
...
?>
Which is quite like the code above - I just use the Set class and make sure to Controller::set the variable to the view.
Also added some basic sorting to show you one option even though array sorting has nothing really specific to do with CakePHP.
Also fixed some bad variable names where I had originally used $venues, and $restaurants - changed to be consistently $v and $r.
Join will not work if there's no relation between. Venue and Restaurant. You should call them separately and merge the results
$venues = $this->Event->Venue->find('list', $venueOptions);
$restaurants = $this->Event->Restaurant->find('list', array('conditions' => array('is_venue' => '1')));
$results = array_merge($venues, $restaurants);
// sort results
asort($results);