+ Start a Discussion

REST API Response Issue

Hi Guys,

I am facing an issue when sending a request to using REST API & the response which i am seeing in the Response status is "Unprocessable Entity" & code is 422.User-added image
Could you please help me in solving this.


VinayVinay (Salesforce Developers) 
Hi Srinivas,

Check if the format is correct like request.setHeader('Content-Type', 'application/json); in request header.   Also make sure you have missed any required fields that need to be sent in body.

I checked req header which is in proper format.

HttpRequest req = new HttpRequest();        
                      req.setEndpoint(this.bitty.Endpoint__c + '/apply');        
                      req.setHeader('Authorization', 'Bitty ' + this.accessToken);        
                      req.setHeader('Content-Type', 'application/json');          
                      req.setBody(JSON.serialize(new Request(this.opportunityId)));                      
                      return req;  

I didn't miss any required fields in the body,

Could you please look in to this.  
Suraj Tripathi 47Suraj Tripathi 47

This error is occurring due to your header attribute Content-Type.
Please check the value of this attribute.
If your request has a body of JSON, then the value of the attribute should be 'application/json'.

If you find your Solution then mark this as the best answer. 

Thank you!

Suraj Tripathi
Hi Suraj,

Thanks for quick reply,

If you see my header on top i added req.setHeader('Content-Type', 'application/json');
Endpoint=https://dev.bittyadvance.com/api/submit, Method=POST

I am getting my body in the normal format which is " Request body is--
"state":"New York",
                              "state":"New York",
                              "city":"New York",
                              "cell_phone":"(551) 232-0965",
                              "address2":"112 W 34th St\r\nNew York , NY",
                              "address":"112 W 34th St\r\nNew York , NY"},

   "legal_name":"test 6 by 19",
   "city":"New York",
 "address2":"112 W 34th St\r\nNew York , NY",
 "address":"112 W 34th St\r\nNew York , NY"}.

Could you please let me know, where the issue lies here. I am bit confused.

I tried making some changes let's say in the body, i was giving the above text as hard coded, so now i was able to see there is a change response System.HttpResponse[Status=Not Found, StatusCode=404], may i know what does this mean please ? Appreciate, your help!