function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
bingi crm 7bingi crm 7 

I am try to box.com integration hiting error":"unauthorized_client","error_description":"The grant type is unauthorized for this client_id"

I am try to integrated the values of this my code get json respons will not access throw the showing error
       error":"unauthorized_client","error_description":"The grant type is unauthorized for this client_id"
RestApi:
Class:-
public class Trybox {
   public string temp{get;set;}
    public PageReference Getauth() {
        return new PageReference('https://account.box.com/api/oauth2/authorize?response_type=code&client_id=wx7fximheqlekhc5e8ffiu14oa70o7m2');
    }

   public void Getauthen(){
        string code = apexpages.currentpage().getparameters().get('code');
    HttpRequest req = new HttpRequest();
     //searchtext.replaceAll(' ','+');
     req.setEndpoint('https://api.box.com/oauth2/token');
     req.setMethod('POST');
      req.setHeader('Accept','application/json');
     req.setBody('grant_type=authorization_code&code='+code+'&client_id=wx7fximheqlekhc5e8ffiu14oa70o7m2&client_secret=Ip8tJlTRAROhb6HMZ0uE1E7Uo8p0gsKb');
     Http http = new Http();
    HTTPResponse res = http.send(req);
       temp = res.getBody();
    }
}
visualforce:-
<apex:page controller="Trybox">
<apex:form >
<apex:commandButton value="Get Auth" action="{!Getauth}"/>
</apex:form>
 </apex:page>
User-added image
Amit Singh 1Amit Singh 1
Try adding the below line
req.setHeader('Content-Type','application/x-www-form-urlencoded');
let me know if this helps :)
Thanks!
AMit Singh
 
bingi crm 7bingi crm 7
No Its not working Bro.