0

I've been trying to send a post request to https://streamlabs.com/api/v2.0/donations with the access token from user settings (note that i didnt register my app but i am just going to use it for my own app so there seems to be no use to do so | https://dev.streamlabs.com/reference/authorize) but I keep getting a 401 response from the streamlabs server stating that the authentication failed because the token was invalid. I copied the entire token of 250 length and pasted it in the bearer header. Here is my code in kotlin which is modified version of their own snippet on https://dev.streamlabs.com/reference/donations-1:

val jsonPayload = JSONObject().apply {
    put("skip_alert", "no")
    put("name", notification.senderName)
    put("message", notification.message)
    put("amount", notification.amount)
    put("currency", "USD")}
            
    Log.d(TAG, "Request payload: $jsonPayload")
    val mediaType = "application/json".toMediaTypeOrNull()
    val body = jsonPayload.toString().toRequestBody(mediaType)
    val request = Request.Builder()
        .url("https://streamlabs.com/api/v2.0/donations")
        .post(body)
        .addHeader("accept", "application/json")
        .addHeader("content-type", "application/json")
        .addHeader("Authorization", "Bearer $apiToken")
        .build()
    client.newCall(request).execute().use { response ->
        val responseBody = response.body?.string()
        val responseCode = response.code

and here is the logcat output of tag:filename :

2025-03-02 00:53:55.370 23294-23294 AlertsApi    com.example.upialerts    D  Starting test alert
2025-03-02 00:53:55.371 23294-23346 AlertsApi    com.example.upialerts    D  Starting API call with token length: 250
2025-03-02 00:53:55.371 23294-23346 AlertsApi    com.example.upialerts    D  First 4 chars of token: ****...
2025-03-02 00:53:55.371 23294-23346 AlertsApi    com.example.upialerts    D  Request payload: {"skip_alert":"no","name":"Test Donation","message":"This is test donation","amount":1,"currency":"USD"}
2025-03-02 00:53:55.374 23294-23346 AlertsApi    com.example.upialerts   D  Request URL: https://streamlabs.com/api/v2.0/donations
2025-03-02 00:53:55.374 23294-23346 AlertsApi    com.example.upialerts   D  Request headers: accept: application/json
content-type: application/json
Authorization:
2025-03-02 00:53:55.802 23294-23346 AlertsApi    com.example.upialerts   D  Response code: 401
2025-03-02 00:53:55.803 23294-23346 AlertsApi    com.example.upialerts   D  Response headers: date:
content-type: text/html; charset=UTF-8
cache-control: no-cache, private
access-control-allow-origin:*
access-control-allow-methods: GET, POST, PUT, DELETE, OPTIONS
access-control-allow-headers: authorization, content-type
cf-cache-status: DYNAMIC
set-cookie:
server: cloudflare
cf-ray:
2025-03-02 00:53:55.803 23294-23346 AlertsApi     com.example.upialerts  D  Response body: Unauthorized.
2025-03-02 00:53:55.803 23294-23346 AlertsApi     com.example.upialerts  E  API call failed with code: 401
2025-03-02 00:53:55.803 23294-23346 AlertsApi     com.example.upialerts  E  Error response: Unauthorized.
2025-03-02 00:53:55.803 23294-23346 AlertsApi     com.example.upialerts  E  Authentication failed - Invalid token
B L — Today at 01:26 AM
2
  • idk if the access_token received from the get request using the /authorise endpoint is different from the access token found in user settings Commented Mar 2 at 11:15
  • it appears that i completely misunderstood how oauth2 works and that i had to give my app donations.create scope in order to even send something. Commented Mar 4 at 17:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.