+ Start a Discussion
Sri549Sri549 

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.

Thanks!
Srinivas

 
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.

Thanks,
Sri549Sri549
I checked req header which is in proper format.

HttpRequest req = new HttpRequest();        
                      req.setEndpoint(this.bitty.Endpoint__c + '/apply');        
                      req.setMethod('POST');        
                      req.setTimeout(60000);        
                      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
Hi,
Greetings!

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!

Regards,
Suraj Tripathi
Sri549Sri549
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--
{"zip":"10120",
"state":"New York",
"start_date":"2014",
                              "owner":{"zip":10120,
                              "state":"New York",
                              "last_name":"test",
                              "first_name":"test",
                              "email":"nikhilg113114@gmail.com",
                              "dob":"1991",
                              "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",
   "leadId":"0061h00000HsAprAAF",
   "ein":"90-0000000",
   "city":"New York",
  "apikey":"dwVXv0S!QcmPJoU2pkWf!nHTEhbOus^D$%679K^&gRxF3rZLyeYjt%GA&NM5$zBCaql48",
 "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.

Thanks!
Srinivas
Sri549Sri549
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!