Skip to content

Instantly share code, notes, and snippets.

@TerribleDev
Created July 27, 2021 22:11
Show Gist options
  • Save TerribleDev/cf81bb866a0ee2a60b2e1024e4a9f326 to your computer and use it in GitHub Desktop.
Save TerribleDev/cf81bb866a0ee2a60b2e1024e4a9f326 to your computer and use it in GitHub Desktop.
Calling Quala API from UnityWebRequest
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
public class Main
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void OnBeforeSceneLoadRuntimeMethod()
{
var payload = "{ \"type\": \"identify\", \"traits\": { \"name\": \"testProfile\" }, \"userId\": \"986\", \"companyId\": \"12345\", \"companyTraits\": { \"name\": \"Development Test\" } }";
using (var request = new UnityWebRequest("https://beacon.quala.io/v1/identify", "POST"))
{
byte[] bodyRaw = Encoding.UTF8.GetBytes(payload);
request.SetRequestHeader("Authorization", "writeKey: YourWriteKey");
request.SetRequestHeader("Content-Type", "application/json");
request.uploadHandler = new UploadHandlerRaw(bodyRaw);
request.downloadHandler = new DownloadHandlerBuffer();
request.SendWebRequest();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment