You need to sign in to do that
Don't have an account?
AKM123
Rest Http Callout setbody error
Hi
I am trying to make a http call to onedrive, I am getting error stating that I have not put grant_type parameter in the setBody although I put it
This is how I written
req.setBody('{"grant_type"="'+AuthToken+'","client_id"="'+client_id+'","redirect_uri"="'+redirect_uri+'","client_secret"="'+client_secret+'","refresh_token"="'+refresh_token+'","resource"="'+resource_id+'"}');
This is the requirement
POST https://login.microsoftonline.com/common/oauth2/token
Content-Type: application/x-www-form-urlencoded
BODY:
client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret} &refresh_token={refresh_token}&grant_type=refresh_token&resource={resource_id}
Thanks in advance
I am trying to make a http call to onedrive, I am getting error stating that I have not put grant_type parameter in the setBody although I put it
This is how I written
req.setBody('{"grant_type"="'+AuthToken+'","client_id"="'+client_id+'","redirect_uri"="'+redirect_uri+'","client_secret"="'+client_secret+'","refresh_token"="'+refresh_token+'","resource"="'+resource_id+'"}');
This is the requirement
POST https://login.microsoftonline.com/common/oauth2/token
Content-Type: application/x-www-form-urlencoded
BODY:
client_id={client_id}&redirect_uri={redirect_uri}&client_secret={client_secret} &refresh_token={refresh_token}&grant_type=refresh_token&resource={resource_id}
Thanks in advance
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_json_jsongenerator.htm
2) https://developer.salesforce.com/page/Getting_Started_with_Apex_JSON
Option 1:-
You can also convert the JSON to APEX.
1) https://www.adminbooster.com/tool/json2apex
Try to create the wrapper class for your JSON with above link and try below code.
Option 2:-
RestRequest req = new RestRequest();
req.httpMethod = 'POST';
req.addHeader('Content-Type', 'application/json'); // Add a JSON Header as it is validated
req.requestURI = '/services/apexrest/api/*/URL' ;
req.requestBody = Blob.valueof(JSONBody); // Add JSON body
RestContext.request = req;
RestContext.response = res;
Let us know if this will help you
Thanks
Amit Chaudhary