---
title: API Quality Check
slug: smart-care/api-quality-check
docTags: 
createdAt: 2025-06-03T09:18:12.636Z
---

| **Information** |                                                                                  |
| --------------- | -------------------------------------------------------------------------------- |
| Description     | Code snippet for calling the v1/smartcare/check API endpoint for a single image. |
| Purpose         | The function:<br />* Uploads a JPG-encoded image as multipart/form-data          |
| Language        | Kotlin                                                                           |

### Input Parameters

- jpegBytes: `ByteArray`
  &#x20;The raw data containing the compressed JPG image.

### Output

- errorCode: `int`&#x20;
  &#x20;Integer value representing the type of quality error. Set to 0 when quality check passed.
- errorType: `string`
  &#x20;String value representing the type of quality error. Set to "pass" when quality check passed.

### Snippet

```kotlin
fun uploadJpegToApi(jpegBytes: ByteArray, apiUrl: String) {
    val client = OkHttpClient()

    // Create multipart body
    val requestBody = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addHeader("Authorization", "Token <your_action_token>")
        .addFormDataPart(
            "image",               // Field name
            "frame.jpg",           // File name
            RequestBody.create("image/jpeg".toMediaTypeOrNull(), jpegBytes)
        )
        .build()

    // Build POST request
    val request = Request.Builder()
        .url(apiUrl)
        .post(requestBody)
        .build()

    // Execute request asynchronously
    client.newCall(request).enqueue(object : Callback {
        override fun onFailure(call: Call, e: IOException) {
            Log.e("API", "Failed to upload image", e)
        }

        override fun onResponse(call: Call, response: Response) {
            response.use {
                if (!response.isSuccessful) {
                    Log.e("API", "Unexpected HTTP code: ${response.code}")
                    return
                }

                val responseBody = response.body?.string()
                Log.d("API", "Response: $responseBody")

                // Example response: {"error_code": 0, "error_type": "PASS"}
                val json = JSONObject(responseBody ?: "{}")
                val errorCode = json.optInt("errorCode")
                val errorType = json.optString("errorType")

                Log.d("API", "Error Code: $errorCode, Error Type: $errorType")
            }
        }
    })
}
```

### Notes

- The snippet above uses the `OkHttp` dependency for handling the HTTP request.

