You need to sign in to do that
Don't have an account?
Board salesforce
Hi am getting the following error can any one help out.
16:56:12:643 USER_DEBUG [49]|DEBUG|jsonFolderResponse{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value '{\"name\":\"Test\",\"Parent\":\" {\"id\":\"0\"}\"}'. Entity body should be a correctly nested resource attribute name\/value pair"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"62736846156efda548b4e5"}
Thanks,
Ram
Creation of folder in box from salesforce
public void CreateFolder(){ //BoxFolder folder = new BoxFolder('bbwh00nt6dylw1w8y1z7p0dnm4zd2m8n', '"Parent": {"id":"0"}'); HttpRequest request=new HttpRequest(); request.setendpoint('https://api.box.com/2.0/folders'); request.setmethod('POST'); request.setHeader('Authorization','Bearer ' + AccessToken); string body= '{"name":"test", "parent": {"id": "0"}}'; request.setBody(body); Http p=new Http(); HttpResponse response=p.send(request); jsonFolderResponse=response.getBody(); System.debug('jsonFolderResponse'+jsonFolderResponse); }
Hi am getting the following error can any one help out.
16:56:12:643 USER_DEBUG [49]|DEBUG|jsonFolderResponse{"type":"error","status":400,"code":"bad_request","context_info":{"errors":[{"reason":"invalid_parameter","name":"entity-body","message":"Invalid value '{\"name\":\"Test\",\"Parent\":\" {\"id\":\"0\"}\"}'. Entity body should be a correctly nested resource attribute name\/value pair"}]},"help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Bad Request","request_id":"62736846156efda548b4e5"}
Thanks,
Ram
If you try to run this with cURL, does it succeed as expected?
Thanks for the Response,
I have tried this above code in apex i got the above error .can you please help me out in creation of folder in box from salesforce with sample code that you have succeeded.
Thanks,
Ram
Based on the error message you have in your inital post it looks like it may be that your access token has expired. You can try to add the following to your code to see all the resulting headers to see if there is more information there.
Awesome that works fine.
here i have an issue which try to integrate with trigger ,class with callout method ,i am unable to hold the code until or unless i click grant access now i want to skip grant access step directly in backend to genrate code and follow on with access token..can you help me out
Yes absolutely you are right can you please help out
[1] http://stackoverflow.com/questions/3324238/what-is-the-difference-among-basicauth-oauth-and-xauth
is there any other way to do?any related code to store authcode and token generation using cURL?that helps me a lot
Just a side note about custom settings, you will have to create them inside your test classes. They live in a kind of half place between data and metadata and are not accessable via tests (without seeAllData) unless you create them first.
[1] https://labs.hybris.com/2012/06/18/trying-out-oauth2-via-curl/
[2] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_custom_settings.htm
[3] https://help.salesforce.com/apex/HTViewHelpDoc?id=cs_accessing.htm&language=en
[4] https://help.salesforce.com/HTViewHelpDoc?id=cs_limits.htm&language=en_US
Curl is the thing in command prompt,i want it using apex and api based is their any other way to aprroach this ?
Setup
- Call Visualforce page the redirects for oAuth login
- Approve application
- Return from oAuth flow to Visualforce page
- Store access_token from payload into custom setting
Account trigger (on insert)Pcon Can u help with this error i commented
If you are referring to thses lines it's because you don't have an entry with the name CredentialsBox. If you run the following in the Developer Console's anonymous Apex, you can see a list of all the possible values
These are case sensitive. You can also run
to see if the getValues call is returning null.
NOTE: Next time, please seperate these out into their own code samples (you can have multiple per post) and include the line number that you are seeing there error
i think you didnt get it,
Call Visualforce page the redirects for oAuth login
Approve application
Return from oAuth flow to Visualforce page
Store access_token from payload into custom setting
As you mentioned these are the steps to follow i agree
first we have to athuorise by entering box credentials(grantaccess) every time But here in trigger am unable to skip the grantaccess step
BoxLogin.vfp
BoxController.cls
BoxInsert.trigger
- Save these files
- Add api.box.com to your Remote Site Settings
- Goto /apex/BoxLogin
- Click Login
- You should see "Already has token" (It might refresh the page and Login still shows up. If that happens just refresh the page)
- Insert an account
- View that folder has been created in your box.com account
After this, every time you insert an account, it will pull the access_token from the custom setting. What this does not cover is how to regenerate the access_token with the refresh_token. I'll leave that up to you. Worst case, you delete the Access_Token__c from your credentials custom setting and then revisit the BoxLogin page to generate a new one.mismatch redirect_uri error ?vf page name will be the redirect_uri?
HttpRequest req = new HttpRequest();
Http h=new Http();
String jsonData = '{"parents":[{"id":"root"}],"name":"DynamictTestWNF", "mimeType":"application/vnd.google-apps.folder"}';
req.setBody(jsonData);
req.setMethod('POST');
req.setEndpoint('https://www.googleapis.com/drive/v3/files');
req.setHeader('Content-length', String.valueOf(jsonData.length()));
req.setHeader('Content-type', 'application/json');
req.setHeader('Authorization', 'Bearer '+accessToken);
HttpResponse res = h.send(req);
System.debug('Response:- '+res.getBody());
We need to replace Id "0" to "root". So please put the "root" in JSON Body and check it.
Thanks,
Shailendra