Errors

When something goes wrong with an API request, the server returns an error. The HTTP response header includes the error code, and the response body contains the error message.

Processing of the query may fail at two separate stages:

Successful query

The following query fetches the email address of the current user:

QUERY='{
  "query": "query {
      currentUser {
          email
      }
  }"
}'
curl -X POST https://${account}.my.rubrik-lab.com/api/graphql \
--header "authorization: Bearer ${access_token}" \
--header "content-type: application/json" \
--data "$(echo $QUERY)"

The response is a JSON object where the data field contains the response data:

{
   "data" : {
      "currentUser" : {
         "email" : "happy.user@rubrik.com"
      }
   }
}

Malformed query

Following is an example of a malformed query, where the name of the email field is misspelled as eamil.

{
  "query": "query {
      currentUser {
          eamil
      }
  }"
}

Repeat the curl command with this input query.

The response header contains the 400 error code, indicating a bad request. The body of the response looks as follows:

{
   "code" : 400,
   "message" : "[QueryAnalysisError] [UserManagement Team] Encountered Client error (400) executing query with operations: [] and variables {}. Error: Query does not pass validation. Violations:\n\nCannot query field 'eamil' on type 'User'. Did you mean 'email'? (line 1, column 23):\nquery { currentUser { eamil } }\n                      ^",
   "traceSpan" : { ... },
   "uri" : "/api/graphql"
}

Where code is the HTTP status code.

HTTP error codes ranging from 400-499 indicate client-side errors, while the HTTP error codes ranging from 500-599 are server-side errors. More information on error codes and their meaning is available at httpstatuses.com.

message field contains a human-readable explanation of the issue the query has encountered.

Erroneous query

A query is erroneous if it cannot be successfully completed by the server, due to either the server malfunction or a client-side error. For example, a query that looks up a non-existing object qualifies as erroneous.

The following query is looking for the status of an awsNativeAccount object whose Rubrik ID is the value indicated by the awsNativeAccountRubrikId argument. In this example, the Rubrik ID is a randomly generated UUID that does not represent a valid AWS Native account.

{
  "query": "query {
    awsNativeAccount(
        awsNativeAccountRubrikId: \"7f86b446-dfee-44c5-9a1e-52a7b92b0ab3\",
        awsNativeProtectionFeature: EC2) {
            status
        }
    }"
}

The Rubrik API server responds with an HTTP status code of 200 OK. The response body looks as follows:

{
   "data" : null,
   "errors" : [
      {
         "extensions" : {
            "code" : 403,
            "trace" : { ... }
         },
         "locations" : [
            {
               "column" : 9,
               "line" : 1
            }
         ],
         "message" : "Objects are not authorized",
         "path" : [
            "awsNativeAccount"
         ]
      }
   ]
}

Where:

Summary

To summarize, the following algorithm can be used when establishing whether a query is successful: