Service Responses

Service Responses

Service Responses

When an API is invoked, the API MUST provide a response to the request. Depending on the verb being used, the response MAY include a response body.

The following sections provide information and context regarding status codes, verbs, and general behavior that services SHOULD leverage when providing responses to requests.

Successful Responses (2xx)

Successful responses are those where the service has fulfilled the request. Service responses MUST correspond to the behavior considered proper for a service responding to such a request.

Request VerbRequest Description/ContentResponse CodeResponse Behavior
GETRequests a resource, using information in the URL to provide context and filtering200
”OK”
The service MUST return the resource(s) that corresponds to the request
GETRequests a resource, using information in the URL to provide context and filtering206
”Partial Content”
The service MUST return the partial content that is available, and MUST provide range information for the requester for acquiring the rest of the resource. For the requester to get a valid resource, it MUST continue to query for additional content until the complete resource is fully downloaded.

206 MUST NOT be used when the response is just a subset of a larger set of paginated data (see Pagination / Continuation). In these cases, retrieving more records is optional.

The service MUST include Content-Type and Content-Range headers in its response.

Valid example: ../users/{userId}/profileImage that returns only the first part of the image. The returned data would not be a valid image without additional requests to retrieve the rest of the image.
POST
(create)
Provides the representation of the resource being created201
”Created”
If the service has synchronously created a new resource, the service returns 201 and a full representation of the new resource.

If the service also returns the URI of the created resource in the HTTP header, it MUST return the URI in the HTTP Location header field.

APIs MAY implement mechanisms that allow returning a subset of the full representation (e.g. $select oData System Query option), but the default response MUST be the full representation of the new resource.
POST
(create)
Provides the representation of the resource being created202
”Accepted”
If the service will create the resource asynchronously , the service returns a 202 along with a “task” reference (likely TRN; actual format TBD) that contains information that the client can use to get the status of the resource being created. It MUST be noted clearly in the API endpoint documentation if the client needs to anticipate receiving 202 responses.

Please send a note to api-standard-ug@trimble.com if you need to implement asynchronous resource creation so that a standard “task” block and API can be created.
POST
(search)
200
”OK”
The body of the response contains the results of the search
PUTProvides the updated resource representation that SHOULD update an extant resource, or MUST facilitate the creation of a new resource200
”OK”
This code is returned if the resource already existed and was replaced.
PUTProvides the updated resource representation that SHOULD update an extant resource, or MUST facilitate the creation of a new resource201
”Created”
Same as POST - 201 “Created”
PUTProvides the updated resource representation that SHOULD update an extant resource, or MUST facilitate the creation of a new resource202
”Accepted”
Same as POST - 202 “Accepted”
PATCHProvides the partial updates for the target resource200
”OK”
The service MUST return the full resource representation.

If any part of the PATCH update fails, the service MUST return an appropriate error code and MUST NOT modify the original resource.
PATCHProvides the partial updates for the target resource202
”Accepted”
See POST - 202 “Accepted” for more information on successful handling.

See PATCH - 200 “OK” for how to handle the failure of any update.
DELETEDeletes the specified resource. MUST not permit bulk or mass deletes.204
”No Content”
The service MUST NOT return a body

Client Error Responses (4xx)

Client errors are generated when the requester does something wrong, such as submitting an improperly formatted request or trying to access a resource that does not exist. All client error responses MUST return an error document conforming to the Standard Error Payload.

VerbError ConditionResponse CodeResponse Behavior
ANYThe request contains malformed syntax and cannot be understood by the server400
”Bad Request”
The service MUST return a response body with a clear, unambiguous description of the error and at least one suggestion for how to correct the error.
ANYThe request lacks valid authentication credentials that the service requires401
”Unauthorized”
The service MUST NOT return any information that can be used to compromise credentials or identities.
ANYThe request is valid and acceptable to the service, but it is refusing to fulfill the request. This could be due to an authentication or authorization issue or attempting to execute a prohibited action403
”Forbidden”
The service MUST NOT return any information that can be used to compromise credentials or identities.
GETThe requested resource was not found. (see “Use of Status Code 404 - Not Found”)404
”Not Found”
The service MUST return a response body with a clear, unambiguous description of the error and at least one suggestion for how to correct the error.
DELETE
PATCH
The resource specified was not found.404
”Not Found”
The service MUST NOT return a resource representation.
ANYThe verb specified is not applicable for the requested resource405
”Method Not Allowed”
The service MUST return a response body with a clear, unambiguous description of the error and at least one suggestion for how to correct the error.
GET
PUT
PATCH
POST
The request specified an Accept header value that cannot be fulfilled by the service406
”Not Acceptable”
The service MUST return an informative message in the response body that indicates which formats are acceptable.
ANYThe request cannot be fulfilled due to the current state of the resource409
”Conflict”
The service MUST return information related to the nature of the conflict.

Use of Status Code 404 - Not Found

HTTP response code 404 MUST be returned when the specified resource cannot be located..

When an empty but extant collection is retrieved on a GET or POST to search and/or filter the collection, a 200 - “OK” status code MUST be returned along with an empty array. This is because the resource actually was found (the collection) but was empty.

Below are examples of things not found and the appropriate HTTP response codes:

OperationConditionResponse
GET .../things/123”Thing” with the ID “123” was previously deleted or never existed404
GET .../toysThere is no collection called “toys”404
GET .../toysThere is a collection called “toys” but it’s emptyEmpty Array200
GET .../toys?type=robotThere is a collection called “toys” and there are toys in it but there are no robots.Empty Array200

Server Error Responses (5xx)

Server errors are generated when server-side processing of a request fails for any reason.

VerbError ConditionResponse CodeResponse Behavior
ANYInternal Server Error500The service MUST return a response body with a clear, unambiguous description of the error and at least one suggestion for how to correct the error.
ANYGateway Timeout504The service MUST NOT return any information that can be used to compromise credentials or identities.

5xx error responses MUST return an error document conforming to the Standard Error Payload. 5xx error responses MUST further specify ways for the client to take an actionable next step such as linking to a support ticket page for the service or identifying how to contact support.