Skip to main content
New Member
March 7, 2021
Solved

Help with connecting an api to Unity Game Engine

  • March 7, 2021
  • 15 replies
  • 606 views

Hello everyone! im a game developer and i am making a game for a client that uses klaviyo for subscriptions. now i have handled api requests through unity before but i cannot link it to my account here to see if it works.
Here is my code  through Unity that calls a Post request
 

private IEnumerator SendData()
{
WWWForm form = new WWWForm();
form.AddField("email", emailField.text); // this is the email entered in the UI of the game
form.AddField("api_key", "my_api_key_here");
UnityWebRequest www = UnityWebRequest.Post("https://a.klaviyo.com/api/v2/list/{LIST_ID}/subscribe", form);
yield return www.SendWebRequest();

if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Registered");
}
Debug.Log(emailField.text);
}
}

 like this i get a 404 and i dont know if im doing something wrong with the url. to be honest i have tried it with mailchimp since this is what i have used before and it works ok. any help would be appreciated thanks!

    Best answer by caroline

    Hi @slaga,

    The CORS error is likely a result of hitting Klaviyo’s server-side Lists V2 endpoint via front-end code. Instead, I would suggest using the front-end endpoint described here.

    Best,

    Caroline

    15 replies

    Contributor I
    July 17, 2025

    Unity game engine is the best in the game version to develop it and based on the updation process.

    Contributor I
    August 26, 2025

    Hi everyone, I’m integrating a custom backend API with Unity for a Brawl Stars–style APK mod and I’m stuck on a few things:

     

    Auth: API returns 401/403 intermittently when using UnityWebRequest with Bearer tokens (JWT). Tokens work fine in Postman. Could Unity’s clock skew or header casing be the issue?

     

    Leaderboards: Large JSON payloads sometimes fail with “Response code 200 but empty body” on Android builds (Editor works). Could this be compression/Content-Encoding or HTTP/2?

     

    In-game purchases: Receipt validation endpoint times out only on mobile data; Wi-Fi is fine. Maybe DNS/SSL chain or certificate pinning mismatch?

     

    CORS/preflight: On WebGL test, OPTIONS preflight is rejected (server expects only GET/POST). Any best practices to configure this cleanly?

     

    What I’ve tried so far:

     

    Forced HTTP/1.1, disabled chunked transfer, set explicit Content-Type and Authorization headers.

     

    Added retry with exponential backoff and refreshed JWT 2 minutes before expiry.

     

    Verified server time (NTP) to avoid exp/nbf drift.

     

    Limited leaderboard page size and enabled gzip.

     

    If anyone has a reliable pattern for UnityWebRequest + JWT (or HMAC) with mobile builds, I’d appreciate tips—especially around compression, redirects, and TLS settings. I’m also documenting my test notes and fixes here: https://nulls-brawll.com.br

     

    Thanks!

    Contributor I
    August 26, 2025

    I’ve been working on a small project in Unity and since updating my device to Android 14 I’m facing a couple of problems:

     

    Authentication requests sometimes fail even though tokens are valid.

     

    JSON data for leaderboards loads fine in Editor but comes back empty on mobile build.

     

    Purchase validation randomly times out on mobile data but works on Wi-Fi.

     

    I tried disabling chunked transfer, forcing HTTP/1.1, and refreshing tokens earlier, but the issue still happens on my ASUS device.

     

    While testing, I also checked performance using different builds like Brawl Stars APK mod

    and noticed the same behavior, so it feels more like a Unity + Android 14 compatibility problem rather than just one game.

     

    Has anyone else run into this with Unity networking on Android 14? Any clean fixes that worked for you?

    Contributor I
    August 26, 2025

    Totally agree, Unity is one of the most flexible engines for building and updating game versions. I’ve also been testing it with different builds and mods — for anyone interested, here’s a helpful resource on that: Brawl Stars APK mod

     

    Contributor I
    August 26, 2025

    Unity is definitely one of the easiest engines for updates and testing. I also checked with a custom build of brawl stars and noted some performance changes. For reference I had used this site:
    nullsbrawl-apk-indir.com.tr