HomeGuidesAPI ReferenceChangelog
Log In
API Reference

Responses

Handle Switch API responses by checking HTTP status codes, JSON response payloads, and API error objects.

Handle Switch API responses by checking both the HTTP status code and the JSON response payload.

After you build a request with the conventions in Requests, use this page to parse successful payloads, inspect errors, and decide whether your client should retry, show a validation message, or change the request. If you are choosing where to start, see Getting Started.

Each response includes two layers of status information:

  • HTTP status code: Indicates the protocol-level outcome of the request.
  • Response payload: Contains the application-level status, results, metadata, and any errors.

Response formats

All Switch API responses are returned as JSON. JSON is a lightweight serialization format that is compatible with most programming languages and integration tools.

HTTP status codes

Switch REST APIs use standard HTTP status codes to indicate whether a request succeeded or failed:

HTTP CodeMessageDescription
200OKThe request was processed and returned successfully. Nothing was changed.
201CreatedThe new resource was created successfully.
400Bad RequestProblem with the request, such as a missing, invalid, or type mismatched parameter.
401UnauthorizedThe request did not have valid authorization credentials.
403ForbiddenPrivate data you are not allowed to access, or you have hit a rate limit.
404Not FoundYour URL is incorrect, or the requested resource does not exist.
500Server ErrorWe had a problem handling the request. If this error persists, contact support. We log and review all errors, but your reports often help us fix them more quickly.
503Service UnavailableOur API is down. Please try again. We work hard to make this rare.

Non-20x status codes indicate an error. Use the response payload to find the specific error code and message.

Response payload

Each API response is wrapped in a standard payload that contains the results of the API call and metadata, such as the total count of matching records and the result object type.

This example shows a successful response:

{
  "status": "success",
  "count": 2,
  "type": "LoadServingEntity",
  "results":[ {
    "lseId": 2756,
    "name":"Georgia Power Co",
    "code":"7140",
    "websiteHome":"http://www.georgiapower.com/"
  }, {
    "lseId":1,
    "name":"City of Augusta",
    "code":"1000",
    "websiteHome":null
  }]
}

In this response, the result type is LoadServingEntity and there are two results. The results field is always an array, even when you request one object.

NameTypeDescription
statusStringPossible values are success and error.
countIntegerTotal count of records that match your request. Because of pagination, this is not necessarily the number of records in the response.
typeStringResource (sometimes called the Object) type.
resultsObject[]Contains the object or objects that you requested.

The count property tells you how many items matched your request criteria. The count property is limited to a maximum of 100,000, so interpret a count of 100000 as "100,000 or more." Use count with pagination request parameters.

Response payload changes

From time to time, we may add fields to a particular API endpoint. In general, these new fields appear only when you request the extended field set. However, your API client should be prepared to ignore object properties it does not recognize.

Errors

Errors are returned in the response payload.

Errors in the response payload

The standard response payload can contain one or more errors. Use the error code, message, objectName, and propertyName fields to decide whether to show a validation message, retry the request, or change the request before sending it again.

{
  "status":"error",
  "count":2,
  "type":"Error",
  "results":[{
    "code":"NotNull",
    "message":"An appKey must be supplied",
    "objectName":"requestSignature",
    "propertyName":"appKey"
  }, {
    "code":"NotNull",
    "message":"An appId must be supplied",
    "objectName":"requestSignature",
    "propertyName":"appId"
  }]
}

Error type definition

The Error type has the following data definition:

NameTypeDescription
codeStringError code. This unique string identifies the type of error. Always returned.
messageStringLocalized user-readable message describing the error. Conditionally returned.
objectNameStringType of object related to the error. This is typically a resource type that is part of the response, such as Tariff. Conditionally returned.
propertyNameStringProperty related to the error. Primarily used for binding and validation errors, but sometimes used for business logic errors, such as tariffId or lseId. Conditionally returned.

List of error codes

The code value in an Error object can be any of the following:

NameDescription
ObjectNotFoundTypically this is when the item id you passed in was not found. For example, passing in a non-existent masterTariffId.
NotNullA required object was not passed in on the request. Check the objectName and propertyName for more information.
InvalidArgumentAn argument passed in did not meet validation requirements. This may or may not be related to the request parameters passed in.
InvalidStateThe current state of the object in question prevents the requested action from being performed.
TypeMismatchAn argument was not of the expected type. This may or may not be related to the request parameters passed in.
MissingIdAn ID (usually a masterTariffId) is required to process the request but none was supplied.
DataIntegrityViolationExceptionThe data sent in was not valid. You may see this error when trying to overwrite a value that cannot be overwritten.
InvalidFileFormatThe file format sent in was invalid.
InvalidErrorThe supplied value is not valid.
ObjectCannotBeSavedThere was an error saving the object.
InsufficientPermissionsThe supplied credentials do not have permission to access this resource.
SystemErrorUnexpected exception.
UniquenessViolationErrorYou can only have one object with this ID. Usually seen when trying to create a new object with a providerAccountId or providerProfileId that already exists.
InvalidDateRangeThe date range is not valid. Usually caused by a fromDateTime being after a toDateTime.

Next steps

  1. Review Dates & Times if you receive date-range or time-zone validation errors.
  2. Use Testing & Debugging Overview or Simulate Errors to test your client's error handling before calling resource APIs.
  3. Return to Getting Started to choose the API family that matches your workflow.