Responses

After calling an endpoint method, a data transfer object will be returned containing the response from Amazon, formatted using their schema system.

Generally, Amazon returns one or two root keys: payload and errors. The errors key will be returned as an ErrorListSchema, and the payload will be the appropriate schema for the response.

Data Transfer Objects

Each response is a data transfer object (DTO). Read more about data transfer objects.

The benefit of using DTOs is that the response is typed and standardized, so you have type safety when using the response.

To use a DTO, access the expected results by using object keys. For example:

$subscription = $spa->notifications->getSubscription($notification_type); // GetSubscriptionResponse DTO
$payload = $subscription->payload; // SubcriptionSchema
$errors = $subscription->errors; // ErrorListSchema

$subscription_id = $subscription->payload->subscription_id; // string

Some properties on DTOs are Collections. See the example for the ErrorListSchema to see how you might use a collection.

Any DTO can be transformed into an array by calling toArray on the DTO.

ErrorListSchema

The ErrorListSchema is a collection of ErrorSchema objects. You can use all the collection methods on the ErrorListSchema. For example:

$subscription = $spa->notifications->getSubscription($notification_type); // GetSubscriptionResponse DTO
$errors = $subscription->errors; // ErrorListSchema
$first_error = $subscription->errors->first(); // ErrorSchema
// OR 
$first_error = $subscription->errors[0]; // ErrorSchema - IDE types sometime work better when accessing using an array index
$invalid_client_error = $subscription->errors->where('code', 'invalid_client')->first(); // ErrorSchema

ErrorSchema

The ErrorSchema contains the following keys:

Key Description Type
code An error code that identifies the type of error that occurred. string
message A message that describes the error condition in a human-readable form. string
details Additional details that can help the caller understand or fix the issue. string