The Response Object

Response#

The SkyCiv API will run all the functions you define and respond with a JSON object which contains the results in two components.

  • The response property provides an object containing the results of the last function executed and some additional helpful information.
  • The functions property provides an array of objects where each object contains the results of the respective function.

Consider the functions we provided in the request object in the Creating the API Object section. The functions property in the response will look as follows:

Response structure
{
"response": {
"data": [...], // Analysis results from the last function - S3D.model.solve
"msg": "Non Linear Analysis Successfully Ran",
"status": 0, // 0 indicates success, 1 indicates fail.
"session_id": "ttaAi9xJSTPwvfzqFmpEiqAYBtf01e7HA3im8toHo4Vgy7y5Q6EgnBU5fk9yrfMC",
"monthly_api_credits": {
"quota": 6000,
"total_used": 22,
"used_this_call": 1
}
},
"functions": [
{}, //response for S3D.session.start
{}, //response for S3D.model.set
{} //response for S3D.model.solve
]
}


Interpreting the response#

The API call will provide a response which we conventionally name res or response as shown in the previous section. After parsing this to a JSON object (turning the text into a structured object), we can read the data shown in the code block below.

If data.response.status equals 0, then all functions have been successfully executed. If the response is greater than or equal to 1, this indicates unsuccessful execution or one or more functions.

/*
In the previous section, we received a variable
called res which we then parsed as JSON.
*/
const parsedResults = JSON.parse(responseData);
// We can dig down into this variable by "chaining" the keys within the object.
// If our JSON response object looks like this:
{
"response": {
"data": [...], // analysis results
"msg": "Non Linear Analysis Successfully Ran",
"status": 0,
"session_id": "ttaAi9xJSTPwvfzqFmpEiqAYBtf01e7HA3im8toHo4Vgy7y5Q6EgnBU5fk9yrfMC",
"monthly_api_credits": {
"quota": 6000,
"total_used": 22,
"used_this_call": 1
}
},
"functions": [
{...}, //response for S3D.session.start
{...}, //response for S3D.model.set
{...} //response for S3D.model.solve
]
}
// Then we could do the following to print the value assigned to the "msg" key.
console.log(parsedResults.response.msg)
// Prints: Non Linear Analysis Successfully Ran
// If we needed to retrieve a value from the "S3D.model.set" function then we would access it
// differently as it is an array (denoted by the square brackets)
console.log(parsedResults.functions[1].some_key) // Don't forget arrays start at 0.