Ask a Question
Back to All

Internal Server Error (500) when Making API Call in Kotlin Android Application

Title: Internal Server Error (500) when Making API Call in Kotlin Android Application

Problem Description:

I am encountering an issue when making an API call within my Kotlin Android application. Previously, I used a different approach to perform the API call, which resulted in a 400 Bad Request error due to validation failures. Following some suggestions, I modified my code to follow a similar structure as provided in a Kotlin example from the API documentation. However, this change led to a new problem - I am now receiving a 500 Internal Server Error response.

Previous Approach (Resulting in 500 Internal Server Error):

Initially, I attempted to make the API call using the OkHttpClient and Request classes. Here is a snippet of the code I used:

val client = OkHttpClient()

val mediaType = MediaType.parse("application/json")
val body = RequestBody.create(
    "{\"answer\":{\"type\":\"answer\",\"sdp\":\"${desc.description}\"}, \"session_id\":\"${data.sessionId}\"}}"
val request = Request.Builder()
    .addHeader("accept", "application/json")
    .addHeader("content-type", "application/json")
    .addHeader("authorization", "Basic Ylc5aGRHRjZMbTV2WVcxaGJqRXlRR2R0WVdsc0xtTnZiUTp4TDVWeFN0Mzh0ZmIwbzFYbEhyaUM=")

val response = client.newCall(request).execute()

Current Approach (Also Resulting in 500 Internal Server Error):

After facing the validation failure issue with the previous approach, I adopted a different approach based on a Kotlin example provided in the API documentation. Here is the modified code snippet:

    startSteamRequest =
    "{\"answer\":{\"type\":\"answer\",\"sdp\":\"${desc.description}\"}, \"session_id\":\"${data.sessionId}\"}}"
    , id = data.id
).enqueue(object : Callback<String> {
    override fun onResponse(call: Call<String>, response: Response<String>) {
        // Handle response

    override fun onFailure(call: Call<String>, t: Throwable) {
        // Handle failure

Issue Details:

Despite trying both approaches, I consistently encounter a 500 Internal Server Error response. The error message does not provide much insight into the root cause of the problem. I have double-checked the request payload and headers, but I'm unable to identify the source of the error.

Request for Assistance:

I would appreciate any guidance or suggestions on how to troubleshoot and resolve this persistent 500 Internal Server Error. Specifically, I am seeking advice on:

Potential causes of the 500 Internal Server Error in this context.
How to effectively debug and diagnose the issue within the Android application.
Any best practices or recommendations for making API calls in Kotlin Android applications.

Additional Information:

Programming Language: Kotlin
API Endpoint: https://api.d-id.com/talks/streams/{id}/sdp


I am eager to understand and resolve this issue to ensure the smooth functioning of my Kotlin Android application. Any assistance or insights from the community would be highly appreciated. Thank you in advance for your help.