Go REST
K

422 Unprocessable Entity

Karan Gowda about 4 years ago 5043 views 5 replies

The status code returned was not expected: 422 Unprocessable Entity

for below APEX code
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setEndpoint('https://gorest.co.in/public/v2/users');
request.setMethod('POST');
system.debug('testbody'+json.serialize(postwrap));
request.setBody('{name:Tenali Ramakrishna, gender:male, email:tenali.ramakrishna213@15ce.com, status:active}');
request.setHeader('Authorization', 'Bearer f5d6b292ba8c2a7e26ce1fa8e3d546894389696fafffda0abe0f8439ddff53ec');
HttpResponse response = http.send(request);
if(response.getStatusCode() != 201) {
System.debug('The status code returned was not expected: ' + response.getStatusCode() + ' ' + response.getStatus());

    } else {
        System.debug(response.getBody());
    }
5 replies
Z
zeevy about 4 years ago

https://gorest.co.in/my-account/logs

Can you please check the logs here and post the request body and response

E
Evyatar Ashraf about 4 years ago

Hi I ran into the same issue, I was trying to create a user but be cause i have already used the same email before i was prevented from doing that.
I made sure that the user was deleted before trying again.

(POST /users)
Req body: {id:63e80cf8-d1e9-11ec-9d64-0242ac120002,name:Second User,email:2User@rolfson.net,gender:female,status:active}

Res body: [{field:email,message:has already been taken}]

(GET/DELETE /users/same id): {
message: Resource not found
}

Z
zeevy about 4 years ago

If you have created or modified exiting record you need to pass the access token in GET call to get that object.

E
Evyatar Ashraf about 4 years ago

Thank you very much for the quick reply, I did pass the access token, both from my code and the Go REST console

step 1: created a user => works good
step 2: deleted the user => works good
step 3: re create the user => doesnt work
here is the full request body:
Method: POST
URL: https://gorest.co.in/public/v2/users
Headers: {
Connection: keep-alive,
Content-Type: application/json,
Authorization: Bearer d1ee6ed93b96e64d69a8cc8232c2d103bb54ae5465fb8f9bfcdaa1fce8ff2381,
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.64 Safari/537.36,
accept: application/json,
accept-encoding: gzip, deflate,
content-length: 130
}
Body: {id:3870c22c-d1e9-11ec-9d64-0242ac120002,name:First User,email:1Useri@crooks.name,gender:male,status:inactive}

Z
zeevy about 4 years ago

I followed same thing the REST console, it worked fine for me.

also this user 1User@crooks.name exists in the system

Your reply

Markdown supported