file io - Rename the folder in IOS box v2 api -
the following procedure given in box developer site .
curl https://api.box.com/2.0/folders/folder_id \ -h "authorization: bearer access_token" \ -d '{"name":"new folder name!"}' \ -x put
here code :
nsstring *newdirectoryname; nsstring *str; nsstring*fid = [[boxfilepathsarray objectatindex:0] objectforkey:@"folderid"]; nsstring * type = [[boxfilepathsarray objectatindex:0]objectforkey:@"type"]; nsstring * str_access_token = [[arruseraccounts objectatindex:[dropboxdownloadfileviewcontrolller getsharedinstance].index] objectforkey:@"acces_token"]; if ([type isequaltostring:@"folder"]) { newdirectoryname =tempstring; str = [nsstring stringwithformat:@"https://api.box.com/2.0/folders/%@?access_token=%@",fid,str_access_token]; } else { newdirectoryname = [nsstring stringwithformat:@"%@.pdf",tempstring]; str = [nsstring stringwithformat:@"https://api.box.com/2.0/files/%@?access_token=%@",fid,str_access_token]; } asiformdatarequest *postparams = [asiformdatarequest requestwithurl:[nsurl urlwithstring:str]]; [postparams setpostvalue:newdirectoryname forkey:@"name"]; [postparams setrequestmethod:@"put"]; [postparams startasynchronous]; postparams.delegate = self ; postparams.userinfo = [nsdictionary dictionarywithobject:@"renamefolder" forkey:@"id"];
the response i'm getting :
{ "status" : 400, "help_url" : "http:\/\/developers.box.com\/docs\/#errors", "code" : "bad_request", "request_id" : "169126257953f1ed709ab32", "context_info" : { "errors" : [ { "name" : "entity-body", "message" : "invalid value 'name=dd'. entity body should correctly nested resource attribute name\/value pair", "reason" : "invalid_parameter" } ] }, "message" : "bad request", "type" : "error" }
i got solution. posted json body. here code.
nsstring *newdirectoryname; nsstring *str; nsstring*fid = [[boxfilepathsarray objectatindex:0] objectforkey:@"folderid"]; nsstring * type = [[boxfilepathsarray objectatindex:0]objectforkey:@"type"]; nsstring * str_access_token = [[arruseraccounts objectatindex:[dropboxdownloadfileviewcontrolller getsharedinstance].index] objectforkey:@"acces_token"]; if ([type isequaltostring:@"folder"]) { newdirectoryname =tempstring; str = [nsstring stringwithformat:@"https://api.box.com/2.0/folders/%@?access_token=%@",fid,str_access_token]; } else { newdirectoryname = [nsstring stringwithformat:@"%@.pdf",tempstring]; str = [nsstring stringwithformat:@"https://api.box.com/2.0/files/%@?access_token=%@",fid,str_access_token]; } nsdictionary *cid = [[nsdictionary alloc] initwithobjectsandkeys:newdirectoryname,@"name", nil]; nserror *error; nsdata *postdata = [nsjsonserialization datawithjsonobject:cid options:0 error:&error]; nsmutabledata *data = [[nsmutabledata alloc] initwithdata:postdata]; asiformdatarequest *postparams = [asiformdatarequest requestwithurl:[nsurl urlwithstring:str]]; //[postparams setpostvalue:newdirectoryname forkey:@"name"]; [postparams setpostbody:data]; [postparams setrequestmethod:@"put"]; [postparams startasynchronous]; postparams.delegate = self ; postparams.userinfo = [nsdictionary dictionarywithobject:@"renamefolder" forkey:@"id"];
Comments
Post a Comment