Solve Log Errors : Response status: 422, body: {"message":"Request body is not processable. Please check the errors.}

Nikita35
Kilo Guru

hello 

I am working on minimizing log errors.

here are some 420 errors I see in the logs> Errors which says below:

Response status: 422, body: {"message":"Request body is not processable. Please check the errors.","errors":{"owner":"id or username should be provided"},"took":0.001,"requestId":"7e92211d-5896-4ed7-adbf-1c78f92241fe"}

Source is opsgenie

source script is a script include OpsGenie_Client.

How do I resolve these errors?

10 REPLIES 10

Hi,

you need to check in that script include getAlertFromOpsGenie

In that script include are you consuming any endpoint? if yes then check if owner is set

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

I found Script Include "OpsGenie_Client" in which below function exist:

getAlertFromOpsGenie: function (alertAlias) {

try {
var rest = new sn_ws.RESTMessageV2('x_86994_opsgenie.OpsGenie Alert API Endpoint', 'get');
rest.setRequestHeader("Authorization", "GenieKey " + this.apiKey);
rest.setStringParameter("endPoint", this.endpoint);
rest.setQueryParameter("identifierType", "alias");
rest.setStringParameter("subEndPoint", "/" + alertAlias);
rest.setRequestHeader("Content-Type", "application/json");

gs.debug("Sending GetAlert request to " + rest.getEndpoint());

var response = rest.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var responseLogMessage = "Response status: " + httpStatus + ", body: " + responseBody;

if (!httpStatus.toString().startsWith("2")) {
gs.error(responseLogMessage);
} else {
gs.debug(responseLogMessage);

return responseBody;
}
} catch (ex) {
var message = ex.getMessage();
gs.error("Exception occurred: ", ex);
}
},

I don't see owner though.

Hi,

that owner key is missing

the 3rd party is expecting owner in the json request but you are not sending that

give valid value for owner i.e. user_name of the user

rest.setStringParameter("owner", value);

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Ankur,

Please see my updated function in Script Include "OpsGenie_Client" :

getAlertFromOpsGenie: function (alertAlias) {

try {
var rest = new sn_ws.RESTMessageV2('x_86994_opsgenie.OpsGenie Alert API Endpoint', 'get');
rest.setRequestHeader("Authorization", "GenieKey " + this.apiKey);
rest.setStringParameter("endPoint", this.endpoint);
rest.setQueryParameter("identifierType", "alias");

rest.setStringParameter("owner", user_name);          //////////////Added here


rest.setStringParameter("subEndPoint", "/" + alertAlias);
rest.setRequestHeader("Content-Type", "application/json");

gs.debug("Sending GetAlert request to " + rest.getEndpoint());

var response = rest.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var responseLogMessage = "Response status: " + httpStatus + ", body: " + responseBody;

if (!httpStatus.toString().startsWith("2")) {
gs.error(responseLogMessage);
} else {
gs.debug(responseLogMessage);

return responseBody;
}
} catch (ex) {
var message = ex.getMessage();
gs.error("Exception occurred: ", ex);
}
},

 

This user_name should come from where?

Are there any other changes than the script include?

Hi Nikita,

try sending some hard-coded user name and check what response you get

rest.setStringParameter("owner", gs.getUserName()); 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader