Home Docs C#

C# Quick Start

Integrate Indieop API into your C# games using Unity or .NET.

Prerequisites

Before you begin, make sure you have:

  1. Created an Indieop account
  2. Created a game and obtained your API key from the game settings

Overview

This guide shows you how to send player feedback and form submissions from your C# game to the Indieop API. We'll cover two approaches:

  • Unity: Using UnityWebRequest for Unity games
  • .NET: Using HttpClient for general .NET games

Unity Implementation

Step 1: Create the API Client

Create a new C# script called IndieOpClient.cs in your Unity project:

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

[Serializable]
public class FormField
{
    public string key;
    public string label;
    public string type; // text, dropdown, checkbox, rating
    public string[] options; // Only for dropdown
    public object value;
}

[Serializable]
public class SubmissionData
{
    public string form_name;
    public string tag;
    public string form_type; // general, feedback, bug_report
    public string player_identifier;
    public string game_version;
    public string repository_version;
    public FormField[] fields;
}

[Serializable]
public class ApiResponse
{
    public bool success;
    public string message;
    public ResponseData data;
}

[Serializable]
public class ResponseData
{
    public string submission_id;
    public string form_name;
    public string form_tag;
    public string submitted_at;
    public int fields_count;
}

public class IndieOpClient : MonoBehaviour
{
    private const string BASE_URL = "https://indieop.com/api/sdk";
    private string apiKey;

    public void Initialize(string gameApiKey)
    {
        apiKey = gameApiKey;
    }

    public IEnumerator SubmitForm(SubmissionData submission, Action callback)
    {
        string url = $"{BASE_URL}/submit";
        string jsonData = JsonUtility.ToJson(submission);

        using (UnityWebRequest request = new UnityWebRequest(url, "POST"))
        {
            byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonData);
            request.uploadHandler = new UploadHandlerRaw(bodyRaw);
            request.downloadHandler = new DownloadHandlerBuffer();
            
            request.SetRequestHeader("Content-Type", "application/json");
            request.SetRequestHeader("X-API-Key", apiKey);

            yield return request.SendWebRequest();

            if (request.result == UnityWebRequest.Result.Success)
            {
                try
                {
                    ApiResponse response = JsonUtility.FromJson(request.downloadHandler.text);
                    callback?.Invoke(true, response.message);
                    Debug.Log($"Submission successful: {response.data.submission_id}");
                }
                catch (Exception e)
                {
                    callback?.Invoke(false, "Failed to parse response");
                    Debug.LogError($"Parse error: {e.Message}");
                }
            }
            else
            {
                string errorMessage = request.error;
                try
                {
                    ApiResponse errorResponse = JsonUtility.FromJson(request.downloadHandler.text);
                    errorMessage = errorResponse.message;
                }
                catch { }
                
                callback?.Invoke(false, errorMessage);
                Debug.LogError($"Submission failed: {errorMessage}");
            }
        }
    }
}

Step 2: Use the Client in Your Game

Here's an example of how to use the client to submit player feedback:

using UnityEngine;

public class FeedbackManager : MonoBehaviour
{
    private IndieOpClient client;
    
    void Start()
    {
        // Initialize the client with your API key
        client = gameObject.AddComponent();
        client.Initialize("your_game_api_key_here");
    }

    public void SubmitPlayerFeedback(int rating, string comments)
    {
        SubmissionData submission = new SubmissionData
        {
            form_name = "Player Feedback",
            tag = "feedback",
            form_type = "feedback",
            player_identifier = SystemInfo.deviceUniqueIdentifier,
            game_version = Application.version,
            fields = new FormField[]
            {
                new FormField
                {
                    key = "rating",
                    label = "Overall Rating",
                    type = "rating",
                    value = rating
                },
                new FormField
                {
                    key = "comments",
                    label = "Your Feedback",
                    type = "text",
                    value = comments
                },
                new FormField
                {
                    key = "enjoyed",
                    label = "Did you enjoy the game?",
                    type = "checkbox",
                    value = true
                }
            }
        };

        StartCoroutine(client.SubmitForm(submission, OnSubmissionComplete));
    }

    private void OnSubmissionComplete(bool success, string message)
    {
        if (success)
        {
            Debug.Log("Thank you for your feedback!");
            // Show success message to player
        }
        else
        {
            Debug.LogError($"Failed to submit feedback: {message}");
            // Show error message or retry
        }
    }
}

.NET Implementation (Non-Unity)

For non-Unity C# games, use HttpClient:

using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

public class IndieOpClient
{
    private const string BASE_URL = "https://indieop.com/api/sdk";
    private readonly HttpClient httpClient;
    private readonly string apiKey;

    public IndieOpClient(string gameApiKey)
    {
        apiKey = gameApiKey;
        httpClient = new HttpClient();
        httpClient.DefaultRequestHeaders.Add("X-API-Key", apiKey);
    }

    public async Task SubmitFormAsync(object submissionData)
    {
        try
        {
            string jsonData = JsonSerializer.Serialize(submissionData);
            var content = new StringContent(jsonData, Encoding.UTF8, "application/json");

            HttpResponseMessage response = await httpClient.PostAsync($"{BASE_URL}/submit", content);
            string responseBody = await response.Content.ReadAsStringAsync();

            if (response.IsSuccessStatusCode)
            {
                Console.WriteLine("Submission successful!");
                Console.WriteLine(responseBody);
                return true;
            }
            else
            {
                Console.WriteLine($"Submission failed: {response.StatusCode}");
                Console.WriteLine(responseBody);
                return false;
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
            return false;
        }
    }
}

// Usage example
class Program
{
    static async Task Main(string[] args)
    {
        var client = new IndieOpClient("your_game_api_key_here");

        var submission = new
        {
            form_name = "Player Feedback",
            tag = "feedback",
            form_type = "feedback",
            game_version = "1.0.0",
            fields = new[]
            {
                new
                {
                    key = "rating",
                    label = "Overall Rating",
                    type = "rating",
                    value = 5
                },
                new
                {
                    key = "comments",
                    label = "Feedback",
                    type = "text",
                    value = "Great game!"
                }
            }
        };

        await client.SubmitFormAsync(submission);
    }
}

Field Types Reference

The Indieop API supports four field types:

Field Type Value Type Example
text string "Great game!"
rating int (1-5) 5
checkbox bool true
dropdown string (from options) "Medium"

Best Practices

  • Store your API key securely: Don't hardcode it in publicly accessible code
  • Handle errors gracefully: Implement retry logic for network failures
  • Queue submissions: Store submissions locally if offline and send when connection is restored
  • Rate limiting: Don't exceed 100 requests per minute
  • Include version info: Always send game_version to track feedback by version

Next Steps