Question

Get answers from an inspection

  • 17 August 2023
  • 3 replies
  • 167 views

Badge

When using the api endpoint https://api.safetyculture.io/inspections/v1/answers/{id} to retrieve the responses to an inspection, it returns values for question_id and responses but these don’t seem to correspond to either the template question_id/children_id or the response set ids returned from template and response api endpoints.

I am looking to get the inspection text values for each question/response in from the api.


This topic has been closed for comments

3 replies

Hi.

This can be somewhat confusing, but the text values of the response set answers you’re looking for are present in the template payload.

If you already have the inspection id, you can use this endpoint to get the template data: https://developer.safetyculture.com/reference/templatesservice_gettemplatebyinspectionid 

Then, you can use the id present in the “answers” endpoint response, and find the text you’re looking for in the “template” api response. See example snippets below:

https://api.safetyculture.io/inspections/v1/answers/{id}

{
"result": {
"question_id": "THIS_ID_IS_IRRELEVANT",
"modified_at": "2023-08-18T03:21:49Z",
"question_answer": {
"responses": [
"THIS_IS_THE_ID_TO_CROSS_REFERENCE"
],
"note": "",
"media": [],
"attachments": null
},
"location": null
}
}

 https://api.safetyculture.io/templates/v1/templates/inspections/{inspection_id}

"responses": [
{
"id": "THIS_IS_THE_ID_TO_CROSS_REFERENCE",
"label": "THIS_IS_THE_TEXT_RESPONSE_YOU_ARE_LOOKING_FOR",
"score": 1,
"color": "19,133,95",
"score_enabled": true
},

Please let us know if this answers your question.

Badge

Thanks for the response

I’m still a little confused as to how this would join up……

For clarity I am loading all of this data into sql tables. So I’ve created one table for the inspection answers and one for the templates/inspections as per the endpoints above

It looks like the responses from the endpoint don’t have unique id - so ‘Yes’ would be common across many answers. Same for the template - so ‘Yes’ has the same ID which is an available response across many questions.

So, given the answers, I could say that the answer was ‘Yes’ but I’m still left with a question id that doesn’t link to anywhere to give me the label for what the question was?

Sorry, I missed that in my original message above. I called one of the ids in my example above “irrelevant” when that’s actually the question_id you’re looking for. It’s important to note that the question ids are set per template, not per inspection. The endpoint I suggested does return the TEMPLATE, not the INSPECTION. It just uses inspection_id as an input to find the relevant template.

 

So, going to my example again, with the extra id:

https://api.safetyculture.io/inspections/v1/answers/{id}

{
"result": {
"question_id": "CROSS_REREFENCE_THIS_TO_FIND_QUESTION_TEXT",
"modified_at": "2023-08-18T03:21:49Z",
"question_answer": {
"responses": [
"CROSS_REREFENCE_THIS_ID_TO_FIND_ANSWER_TEXT"
],
"note": "",
"media": [],
"attachments": null
},
"location": null
}
}

 https://api.safetyculture.io/templates/v1/templates/inspections/{inspection_id}

{
"items": [
{
"id": "CROSS_REREFENCE_THIS_TO_FIND_QUESTION_TEXT",
"label": "THIS_IS_THE_QUESTION_TEXT",
"children": [],
"question": {
"options": {
"is_mandatory": false,
"weighting": 1
},
}
],
"responses": [
{
"id": "CROSS_REREFENCE_THIS_ID_TO_FIND_ANSWER_TEXT",
"label": "THIS_IS_THE_RESPONSE_TEXT",
"score": 1,
"color": "19,133,95",
"score_enabled": true
},
]
}