# PetApi All URIs are relative to *http://petstore.swagger.io/v2* | Method | HTTP request | Description | |------------- | ------------- | -------------| | [**getPetById**](PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID | # **getPetById** > Object getPetById(petId) Find pet by ID Returns a single pet ### Example ```java // Import classes: import org.openapitools.client.ApiClient; import org.openapitools.client.ApiException; import org.openapitools.client.Configuration; import org.openapitools.client.auth.*; import org.openapitools.client.models.*; import org.openapitools.client.api.PetApi; public class Example { public static void main(String[] args) { ApiClient defaultClient = Configuration.getDefaultApiClient(); defaultClient.setBasePath("http://petstore.swagger.io/v2"); // Configure API key authorization: api_key ApiKeyAuth api_key = (ApiKeyAuth) defaultClient.getAuthentication("api_key"); api_key.setApiKey("YOUR API KEY"); // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) //api_key.setApiKeyPrefix("Token"); PetApi apiInstance = new PetApi(defaultClient); Long petId = 56L; // Long | ID of pet to return try { Object result = apiInstance.getPetById(petId); System.out.println(result); } catch (ApiException e) { System.err.println("Exception when calling PetApi#getPetById"); System.err.println("Status code: " + e.getCode()); System.err.println("Reason: " + e.getResponseBody()); System.err.println("Response headers: " + e.getResponseHeaders()); e.printStackTrace(); } } } ``` ### Parameters | Name | Type | Description | Notes | |------------- | ------------- | ------------- | -------------| | **petId** | **Long**| ID of pet to return | | ### Return type **Object** ### Authorization [api_key](../README.md#api_key) ### HTTP request headers - **Content-Type**: Not defined - **Accept**: application/xml, application/json ### HTTP response details | Status code | Description | Response headers | |-------------|-------------|------------------| | **200** | successful operation | - | | **400** | Invalid ID supplied | - | | **404** | Pet not found | - |