In cases where the API responds with an error code, the response body will contain additional information about the error.
JSON general error responses will look like this:

{
  "errors": [
    {
      "type": 401,
      "message": "Not authorized."
    }
  ]
}

Error responses to resource-specific operations will associate error messages to resource attributes, like this:

{
  "errors": [
    {
      "type": "InvalidInputSchema",
      "message": "The task input does not match the project schema"
    }
  ]
}

With asynchronous task creation, Sama Platform's requests to the callback URL will not only include the message and type of each error but will also include the request data and the task id.

{
  "success": false,
  "errors": [
    {
      "task_id": "5ebccdc1c49dae54721567a1",
      "type": 400,
      "message": "Invalid seeded output name(s): Bad_Output",
      "request_data": {
        "project_id": 1,
        "questions": {
          "x": 10,
          "y": 30
        },
        "default_answers": {
          "Bad_Output": "40"
        },
        "priority": 3
      }
    }
  ]
}

HTTP Response Codes

Depending on the requested operation, the Samahub API will respond with one of the following HTTP status codes.

200SuccessRequest was processed successfully
201CreatedA new resource was created successfully.
202AcceptedA new resource was accepted for asynchronous creation. We will post the result of the resource creation to the creation callback URL.
302RedirectWe are redirecting you to a resource. The body of this response often contains a message.
400Invalid FormatYou failed to pass one or more required parameters. See body of response for more information.
401UnauthorizedAuthorization failed, check your key. If your key is correct, contact Sama Project Manager to enable API access to your project.
404Resource Not FoundWe could not find the resource (i.e. object) you were looking for, or you do not have access to it.
405Method Not AllowedThe method you are using (GET, POST, PUT, DELETE) is not available from this URL
406Not AcceptableThe format you requested is not available.
409DuplicateTask with primary key has already been received.
422Unprocessable EntityThere was an error creating a resource.
500Internal Server ErrorThis could be the result of improperly formatted JSON.
503Service UnavailableThe project is not in an ‘Active’ state on the Sama Platform.