You need to sign in to do that
Don't have an account?
Test Dev 81
How to fix 422 Unprocessable Entity in httpcallout
hi everyone,
I have created an apex class to make some HTTP callout but when I send the request I am getting error in response
"422 Unprocessable Entity" even though I have put request.setHeader('Content-Type', 'application/json); in request header
Thank You,
Rahul
I have created an apex class to make some HTTP callout but when I send the request I am getting error in response
"422 Unprocessable Entity" even though I have put request.setHeader('Content-Type', 'application/json); in request header
public class Rg_TestMemberAccountCreate { public static void testMemberAccount(String endpoint,String token){ Http http = new Http(); HttpRequest request = new HttpRequest(); request.setEndpoint(endpoint); request.setMethod('POST'); request.setHeader('Content-Type', 'application/json'); request.setHeader('Authorization', 'Bearer '+token); request.setHeader('Accept', 'application/json'); // Set the body as a JSON object String b = '{"data": {"attributes": {"name": "Test Rahul2","symbol": "TESTRT", "is_active": "true"},"type": "providers"}}'; request.setBody(b); System.debug('Requst : '+request); HttpResponse response = http.send(request); System.debug('response: '+response); // Parse the JSON response if (response.getStatusCode() != 200) { System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus()); } else { System.debug(response.getBody()); } } }do you have any idea what is wrong in my class?
Thank You,
Rahul
there are some required fields that need to be sent in body after adding that issus is solved
Thanks, Swetha ,now its working
All Answers
Can you provide the endpoint so I can test this code from my developer console's anonymous block? Thanks
Related:https://stackoverflow.com/questions/16133923/400-vs-422-response-to-post-of-data
https://stackoverflow.com/questions/56711503/how-to-fix-422-unprocessable-entity-when-sending-a-post-request-to-redmine-api
there are some required fields that need to be sent in body after adding that issus is solved
Thanks, Swetha ,now its working