Change folder ownership in Box - box-api

We have a situation where we have 2 users, UserA and UserB. I want to transfer all the files and folders of UserB to UserA.
We are using collaborations API to perform this task. But getting following error
{"type":"error","status":404,"code":"not_found","context_info":{"errors":[{"reason":"invalid_parameter","name":"role","message":"Invalid value 'Owner'. 'role' with value 'Owner' not found"}]},"help_url":"http://developers.box.com/docs/#errors","message":"Not Found","request_id":"304354248562a743910984"}
I get a valid response when I pass anything apart from "owner" as role in request. I don't know what is wrong with "owner" role.
Here is the request
POST https://api.box.com/2.0/collaborations/ HTTP/1.1
As-User: 254598270
Authorization: Bearer UPSUE228kXGuDBGzy07G5fGxIrDL1QDj
Content-Type: text/plain; charset=utf-8
Host: api.box.com
Content-Length: 108
Expect: 100-continue
Accept-Encoding: gzip, deflate
{"item":{"id":"5092905410","type":"folder"},"accessible_by":{"id":"254608030","type":"user"},"role":"owner"}

I think the documentation might be wrong. Specifying an "owner" role in a collaboration doesn't really make sense given how collaborations work.
However, the move user's folder endpoint might be what you're looking for. It allows you to move the entire root folder of one user into another user's account. Here's an example cURL request:
curl https://api.box.com/2.0/users/USER_ID/folders/FOLDER_ID \
-H "Authorization: Bearer ACCESS_TOKEN" \
-d '{"owned_by": {"id": "USER_ID"}}' \
-X PUT
Note that only the root folder is supported right now (which is folder ID 0). Fortunately, it looks like that's the folder you're trying to move.

All that's missing is that you must add them as an editor prior to making them an owner.
If you follow https://developer.box.com/guides/folders/single/change-owner/
You will see that transferring ownership actually doesn't require a folder move. It is a very simple two (or three) step process:
Add the new user as a collaborator of role EDITOR
Immediately update that collaboration to the role of OWNER
That's it. Optionally, you now can remove the collaboration of the original owner, who has been downgraded from owner to editor.
Here is my example using the Python SDK:
bc = box.BoxClient() # This is my own client wrapper
owner = bc.get_user(old_owner.lastname)
user_client = bc.get_user_client(owner.id) # Get a user_client for the owner
src_folder = user_client.folder(FOLDER_ID)
target = bc.get_user('new_owner.lastname')
new_collab = src_folder.collaborate(target, CollaborationRole.EDITOR)
updated_collaboration = new_collab.update_info(CollaborationRole.OWNER)
# Now we can remove the original owner as collaborator:
for collab in src_folder.get_collaborations():
target = collab.accessible_by
if target.id == owner.id:
collab.delete()

Related

Trying to use dev mode with GAS doPOST

I'm trying to test my apps script doPost function, with postman. so far I have:
function doPost(e) {
var id = '1L_U7MhmV............................'
SpreadsheetApp.openById(id).getSheetByName('responses').appendRow([new Date()]);
var params = JSON.stringify(e.parameter);
return ContentService.createTextOutput(JSON.stringify(e.parameter));
}
I can get it working with the /exec string but when I try the /dev string I can't. I'm getting a 500 error. I'm logged into my account and have updated the version number under publish. How can I get this working?
EDIT:
Thank you. I'm trying to option 1. I created a function that logs the oath token:
function getOAuthToken1() {
Logger.log('Current project has ' + ScriptApp.getOAuthToken());
}
I ran it and got the token. Then inserted it into
https://script.google.com/macros/s/ACCESSTOKEN/dev
but posting to this produces:
Sorry, the file you have requested does not exist.
EDIT2:
You want to use doPost() and access to Web Apps with the endpoint of https://script.google.com/macros/s/###/dev.
If my understanding is correct, https://script.google.com/macros/s/ACCESSTOKEN/dev cannot be used as the endpoint. Please use the original endpoint of https://script.google.com/macros/s/###/dev.
As 2 examples for the simple test, when the curl command is used, the sample commands are as follows. You can select one of them and test at your terminal. Both commands use POST method.
curl -L -H "Authorization: Bearer ### access token ###" -d "key=value" "https://script.google.com/macros/s/#####/dev"
or
curl -L -d "key=value" "https://script.google.com/macros/s/#####/dev?access_token=### access token ###"
In order to access to the endpoint of https://script.google.com/macros/s/###/dev of the deployed Web Apps, it is required to use the access token.
Replace ### access token ### to the value retrieved by ScriptApp.getOAuthToken().
Replace https://script.google.com/macros/s/#####/dev to your endpoint retrieved by deploying Web Apps.
I used -d "key=value" for the post method. If you don't want to put the values, please replace to -d "".
Note:
If the error related to the scopes occurs when you test above command, please add the following comment. By this, the scope of https://www.googleapis.com/auth/drive is added.
// DriveApp.getFiles();
After added it, please run the function of getOAuthToken1() again. By this, the access token including the scope can be retrieved.

Deeplinking URLs don't show up in Branch.io Dashboard

I am using branch.io for my android app. I am trying to generate via POST method and this is the code:
{"branch_key":"key_test_lerbZ22zyjfpfFtl2auzukafywi220dN", "campaign":"new_product_annoucement", "channel":"email", "tags":["monday", "test123"],
"data":"{\"name\": \"Alex\", \"email\": \"alex#branch.io\", \"user_id\": \"12346\", \"$desktop_url\": \"https://file.town/download/odrqliwc94d440jt08wxngceo\",\"$marketing_title\": \"2\"}"}
In the dashboard, the campaign can be seen, the channel can be seen, and the generated URL goes to the desired site. But the generated URL does not show up in the Marketing tab in the dashboard to show the URL's statistics with regards to clicks, downloads and installs.
Is there any code I am missing in it?
To use the Branch HTTP API to create a link that shows up in the Marketing section of the Branch dashboard you need to add the parameter "type":2 at the root level of the request. You will also want to use a $marketing_title that is descriptive.
Here is an updated curl request using the parameters you provided:
curl -X POST -H "Content-Type: application/json" -d '{"type":2, "branch_key":"key_test_lerbZ22zyjfpfFtl2auzukafywi220dN", "campaign":"new_product_annoucement", "channel":"email", "tags":["monday", "test123"], "data":"{\"name\": \"Alex\", \"email\": \"alex#branch.io\", \"user_id\": \"12346\", \"$desktop_url\": \"https://file.town/download/odrqliwc94d440jt08wxngceo\",\"$marketing_title\": \"Super Amazing Branch Link\"}"}' https://api.branch.io/v1/url

How can I create curl requests or in Postman (addon) for goa-cellar project

I am beginner to go language. I have downloaded this project (https://github.com/goadesign/goa-cellar) and ran it in local environement. It works well when I make post,get,list calls using goa-cellar client.
Steps:-
go get github.com:goadesign/goa-cellar.git
goagen bootstrap -d
goa-cellar/design go build
Server:-
Start Server -> /.goa-cellar
Following are the sample requests which works well for me using goa-cellar client:
Client:-
Create a account -> ./cellar-cli create account /cellar/accounts --payload '{"name": "test"}'
List account -> ./cellar-cli list account
Show account -> ./cellar-cli show account /cellar/accounts/1
I want to make above request using curl or via Postman (chrome addon) or browser add on. How can I do it ?
I have tried the following:-
1. Create account
Method: POST
URL:- http://localhost:8082
Request body: {"name": "test"}
Request headers:- Content-Type: application/json
Response:-
{
"code": "not_found",
"status": 404,
"detail": "/"
}
Server log:-
INFO[06-23|19:08:25] started req_id=RQLpC8kzbF-2 POST=/ from=127.0.0.1 ctrl=<unknown> action=<unknown>
INFO[06-23|19:08:25] payload req_id=RQLpC8kzbF-2 raw=null
INFO[06-23|19:08:25] completed req_id=RQLpC8kzbF-2 status=404 error=not_found bytes=47 time=97.542µs
Just make sending data to the right HTTP API endpoint, in your case, instead this /, need use to cellar/accounts (http://localhost:8082/cellar/accounts)
By POST you make saving data and by GET + id - retreive data.
Look at README for detail info for using this project.

Unable to import data from CouchDB

I am trying to import and then export data to a remote machine. Here goes the schema of the database. This is just a document that I got it in a form of json.
{"docs":[
{"id":"702decba698fea7df3fa46fdd9000fa4","key":"702decba698fea7df3fa46fdd9000fa4","value":{"rev":"1-f8c63611d5bc7354cac42d2a697ad57a"},"doc":{"_id":"702decba698fea7df3fa46fdd9000fa4","_rev":"1-f8c63611d5bc7354cac42d2a697ad57a","contributors":null,"truncated":false,"text":"RT #Whistlepodu4Csk: : First time since 1987 World Cup no Asian teams in the WC final\nThis had occurred in 1975, 1979, 1987 and now #CWC15\n…","in_reply_to_status_id":null,"in_reply_to_user_id":null,"id":583090814735155201,"favorite_count":0,"author":{"py/object":"tweepy.models.User","py/state":{"follow_request_sent":false,"profile_use_background_image":true,"profile_text_color":"333333","id":3102321084,"verified":false,"profile_location":null,"profile_image_url_https":"https://pbs.twimg.com/profile_images/579460416977252352/weSzVnPF_normal.jpg","profile_sidebar_fill_color":"DDEEF6","is_translator":false,"geo_enabled":false,"entities":{"description":{"urls":[]}},"followers_count":1,"profile_sidebar_border_color":"C0DEED","id_str":"3102321084","default_profile_image":false,"location":"Chennai","is_translation_enabled":false,"utc_offset":null,"statuses_count":9,"description":"12/11","friends_count":23,"profile_link_color":"0084B4","profile_image_url":"http://pbs.twimg.com/profile_images/579460416977252352/weSzVnPF_normal.jpg","notifications":false,"profile_background_image_url_https":"https://abs.twimg.com/images/themes/theme1/bg.png","profile_background_color":"C0DEED","profile_background_image_url":"http://abs.twimg.com/images/themes/theme1/bg.png","name":"charandevaa","lang":"en","profile_background_tile":false,"favourites_count":7,"screen_name":"charandevaarg","url":null,"created_at":{"py/object":"datetime.datetime","__reduce__":[{"py/type":"datetime.datetime"},["B98DFgEtLgAAAA=="]]},"contributors_enabled":false,"time_zone":null,"protected":false,"default_profile":true,"following":false,"listed_count":0}},"retweeted":false,"coordinates":null,"entities":{"symbols":[],"user_mentions":[{"indices":[3,19],"id_str":"570379002","screen_name":"Whistlepodu4Csk","name":"Chennai Super Kings","id":570379002}],"hashtags":[{"indices":[132,138],"text":"CWC15"},{"indices":[139,140],"text":"IndvsAus"}],"urls":[]},"in_reply_to_screen_name":null,"id_str":"583090814735155201","retweet_count":9,"metadata":{"iso_language_code":"en","result_type":"recent"},"favorited":false,"retweeted_status":{"py/object":"tweepy.models.Status","py/state":{"contributors":null,"truncated":false,"text":": First time since 1987 World Cup no Asian teams in the WC final\nThis had occurred in 1975, 1979, 1987 and now #CWC15\n#IndvsAus\"","in_reply_to_status_id":null,"in_reply_to_user_id":null,"id":581059988317073409,"favorite_count":6,"author":{"py/object":"tweepy.models.User","py/state":{"follow_request_sent":false,"profile_use_background_image":true,"profile_text_color":"333333","id":570379002,"verified":false,"profile_location":null,"profile_image_url_https":"https://pbs.twimg.com/profile_images/460329225124188160/FgnIhlVM_normal.jpeg","profile_sidebar_fill_color":"DDEEF6","is_translator":false,"geo_enabled":false,"entities":{"url":{"urls":[{"indices":[0,22],"url":"http://t.co/Kx3erXpkEJ","expanded_url":"http://chennaisuperkings.com","display_url":"chennaisuperkings.com"}]},"description":{"urls":[{"indices":[138,160],"url":"http://t.co/yfitkkfz5D","expanded_url":"http://www.facebook.com/chennaisuperkingsofficialfansclub","display_url":"facebook.com/chennaisuperki…"}]}},"followers_count":13604,"profile_sidebar_border_color":"000000","id_str":"570379002","default_profile_image":false,"location":"Chennai","is_translation_enabled":false,"utc_offset":19800,"statuses_count":13107,"description":"Chennai super kings fans club:All about Mahi, Raina,Mccullum,Aswhin,Bravo. Updates about Suriya: Beleive in CSK: Whistlepodu!Suriya Rocks http://t.co/yfitkkfz5D","friends_count":11962,"profile_link_color":"CCC200","profile_image_url":"http://pbs.twimg.com/profile_images/460329225124188160/FgnIhlVM_normal.jpeg","notifications":false,"profile_background_image_url_https":"https://pbs.twimg.com/profile_background_images/518467484358164480/yUXQYv3m.jpeg","profile_background_color":"FFF04D","profile_banner_url":"https://pbs.twimg.com/profile_banners/570379002/1370113848","profile_background_image_url":"http://pbs.twimg.com/profile_background_images/518467484358164480/yUXQYv3m.jpeg","name":"Chennai Super Kings","lang":"en","profile_background_tile":true,"favourites_count":283,"screen_name":"Whistlepodu4Csk","url":"http://t.co/Kx3erXpkEJ","created_at":{"py/object":"datetime.datetime","__reduce__":[{"py/type":"datetime.datetime"},["B9wFAxUWFAAAAA=="]]},"contributors_enabled":false,"time_zone":"Chennai","protected":false,"default_profile":false,"following":false,"listed_count":23}},"retweeted":false,"coordinates":null,"entities":{"symbols":[],"user_mentions":[],"hashtags":[{"indices":[111,117],"text":"CWC15"},{"indices":[118,127],"text":"IndvsAus"}],"urls":[]},"in_reply_to_screen_name":null,"id_str":"581059988317073409","retweet_count":9,"metadata":{"iso_language_code":"en","result_type":"recent"},"favorited":false,"source_url":"http://twitter.com/download/android","user":{"py/id":13},"geo":null,"in_reply_to_user_id_str":null,"lang":"en","created_at":{"py/object":"datetime.datetime","__reduce__":[{"py/type":"datetime.datetime"},["B98DGgsvMwAAAA=="]]},"in_reply_to_status_id_str":null,"place":null,"source":"Twitter for Android"}},"source_url":"http://www.twitter.com","user":{"py/id":1},"geo":null,"in_reply_to_user_id_str":null,"lang":"en","doc_type":"tweet","created_at":{"py/object":"datetime.datetime","__reduce__":[{"py/type":"datetime.datetime"},["B98EAQIRJgAAAA=="]]},"in_reply_to_status_id_str":null,"place":null,"source":"Twitter for Windows Phone"}}]}
Approach 1:
Here is the command:
curl -d #db.json -H "Content-type: application/json" -X POST http://127.0.0.1:5984/cwc15/_bulk_docs
I get below error:
{"error":"not_found","reason":"no_db_file"}
I did follow below post before I am posting this problem -
https://www.google.com.au/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&cad=rja&uact=8&ved=0CC4QFjAD&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F26264647%2Fcouchdb-exported-file-wont-import-back-into-database&ei=8GMbVY3eNNjo8AW18YL4BA&usg=AFQjCNHdm1o0NS49nKPrEl0zU-n7eVRv8Q&bvm=bv.89744112,d.dGc
And I did not get any help from google. The last post I can see over there is way back in 2012, and I couldn't find the help any good. Could someone please help me out. I could be a life saver for me.
Approach 2 -
curl -H 'Content-Type: application/json' -X POST http://localhost:5984/_replicate -d ' {"source": "http://example.com:5984/dbname/", "target": "http://localhost#:5984/dbname/"}'
Gave my source and the target where I wanted to copy. In target gave the IP address of that machine followed by port no/dbname/
Got error: Connection Timedout
Approach 3:
Exported the couch database with filename - cwc15.couch
Stored in flash drive.
Took root login and went to the location where this file is stored.
Command - cp cwc15.couch /var/lib/couchdb
Get error -
Error:{{case_clause,{{badmatch,
{error,eaccess}},
[{couch_file,init,1,
[{file,"couch_file.erl"},{line,314}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,
239}]}]}},
[{couch_server.handle_info,2,
[{file,couch_server.erl"},{line,442}]},
{gen_server,handle_msg,5,
[{file,"gen_server.erl"},{line,604}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,239}]}]}
{gen_server,call,
[couch_server,
{open,<<"cwc15>>,
[{user_ctx,
{user_ctx,null,
[<<"_admin">>],
<<"{couch_httpd_auth,
default_authentication_handler}">>}}]},
infinity]}
{"error":"not_found","reason":"no_db_file"} - database doesn't exists, you need to create it first: 1 Also, don't use -d curl key for uploading files: that argument is for sending data in text mode, while binary one (-T or --data-binary) is what you really want to. JSON is ineed text format, but Unicode data may play devil role here.
For Connection Timedout error happened because source or target databases aren't reachable by URLs you'd specified. Not sure what they were in real, but localhost#:5984 doesn't looks good one. Also, here you didn't create a database again, so initial error may occur.
The error in your logs {error,eaccess} means bad file permissions which you accidentally broken with copying a file. Follow the install instructions to restore it and ensure that nothing else is broken.

Error when adding existing user to Box enterprise account using Java SDK

I'm trying to add an existing user (a user who registered a personal Box account with his email address) to a Box enterprise account using the Box Java SDK (https://github.com/box/box-java-sdk-v2) like so:
String email = "user#domain.com";
String name = "John Doe";
BoxUserRequestObject boxUserRequestObject = BoxUserRequestObject.createEnterpriseUserRequestObject(email, name);
BoxUser createdUser = boxClient.getUsersManager().createEnterpriseUser(boxUserRequestObject);
However the SDK fails with an error saying:
com.box.boxjavalibv2.exceptions.BoxServerException: User with the specified login already exists
How do I programmatically invite that user to my enterprise account?
It's not possible to do this with box-java-sdk-v2, however I did create an issue for adding this functionality to the latest version of our SDK.
You can also check out the REST API documentation for inviting a user to an enterprise. This endpoint will send an email to a user with a personal account, asking them to join your enterprise.
Here's the example cURL call from the docs:
curl https://api.box.com/2.0/invites \
-H "Authorization: Bearer ACCESS_TOKEN" \
-d '{ "enterprise" : { "id" : "42500" } , "actionable_by" : { "login" : "freeuser#box.com" } }' \
-X POST