Skip to main content
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

 

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

 
2 risposte
  1. 12 apr 2021, 12:07
    Found the issue after trying 5 hrs,

    there are some required fields that need to be sent in body  after adding that issus is solved

    Thanks, Swetha ,now its working
0/9000