422 Unprocessable Entity

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":"[email protected]", "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());
    }

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

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

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":"[email protected]","gender":"female","status":"active"}

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

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

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

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":"[email protected]","gender":"male","status":"inactive"}

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

also this user "[email protected]" exists in the system


Little markdown supported