I want to create share url of a file which is in Box.com using REST API from Apex.
I have written following code
public static Map<Integer, boxShareUrlJson> getShareUrl(String accesstoken,string itemid){
String endpoint = 'https://api.box.com/2.0/files/'+itemid;
String token = EncodingUtil.urlEncode(accesstoken,'UTF-8');
Httprequest request = new Httprequest();
request.setMethod('PUT');
request.setHeader('Authorization','Bearer '+accesstoken);
request.setHeader('Content-Type','application/json');
request.setEndpoint(endPoint);
String postbody = '{"shared_link":"{"access":"open"}}';
request.setBody(postbody);
Http http = new Http();
System.debug(request+'~~~~~~~~~~~~~~~~box share request'+request.getBody());
Httpresponse ApiResponse = http.send(request);
Jsonparser parser = Json.createParser(ApiResponse.getBody());
boxShareUrlJson ContentClass = new boxShareUrlJson(parser);
Map<Integer,boxShareUrlJson> resultMap = new Map<Integer,boxShareUrlJson>();
resultMap.put(ApiResponse.getStatusCode(),ContentClass);
return resultMap;
}
But when I Execute this code I received following error :
System.HttpResponse[Status=Bad Request, StatusCode=400]
Please suggest me where I am wrong or missing something?
Thanks in advance