The CreatorCon Call for Content is officially open! Get started here.

How to add status_message in REST API response on 201 success transaction

Nithish1
Tera Guru

Hello, 

I have a requirement to include the 'status_message' in REST API response body when the third-party web service calls to ServiceNow.  I created an import set API and by using transform map pushing it to the target table. Once data is received through Rest Import set API, the status code is set as 201 Created but here our vendors are looking for 'status_message' as a success. Currently, after a successful transaction, the response body doesn't contain 'status_message' 

Example:

Request

{  
   "u_third_party_ticket_number":"test186725993", //coleasce is true
   "u_incident_state":"6",
   "u_close_code":"Solved (Work Around)",
   "u_close_notes":"test noteshbv"
}

Response:

{
  "import_set": "ISET0010740",
  "staging_table": "u_tr_incident",
  "result": [
    {
      "transform_map": "test",
      "table": "incident",
      "display_name": "number",
      "display_value": "INC0018320",
      "record_link": "https://test.service-now.com/api/now/table/incident/6f9beb2cdb1ef340e01251d7f4961951",
      "status": "updated",
      "sys_id": "6f9beb2cdb1ef340e01251d7f4961951"
    }
  ]
}
Request:
{  
   "u_third_party_ticket_number":"test186725993", //coleasce is true
   "u_incident_state":"6",
   "u_close_code":"00Solved (Work Around)", // invalid value
   "u_close_notes":"test noteshbv"
}
Response:
{
  "import_set": "ISET0010740",
  "staging_table": "u_tr_incident",
  "result": [
    {
      "transform_map": "test",
      "table": "incident",
      "display_name": "number",
      "display_value": "INC0018320",
      "record_link": "https://test.service-now.com/api/now/table/incident/6f9beb2cdb1ef340e01251d7f4961951",
      "status": "skipped",
      "sys_id": "6f9beb2cdb1ef340e01251d7f4961951",
      "status_message": "Choice field value for incident.close_code rejected: 00Solved (Work Around)",
      "error_message": "Choice field value for incident.close_code rejected: 00Solved (Work Around)"
    }
  ]
}
"status_message": "Success", // our vendors need this in the response body. How to achive this?

I can edit response by using scripted REST API butI'm looking something that I can do by using import set api.

Regards,
Nithish


3 REPLIES 3

Harsh Vardhan
Giga Patron

based on the status code you can define the "status_message".

 

Adding one YouTube video link here, kindly have a look on code which has used in the video. 

 

CCB0118 - Taking Import Sets to the Next Level with Scripted REST APIs

 

 

Hello Harsha,

The youtube video link you have shared showed how to edit response by using scripted REST API but I'm looking for something that I can achieve by using an import set API.

 

Thanks,

Nithish

Same thing applied for Import set API as well.