Created
July 27, 2021 22:11
-
-
Save TerribleDev/cf81bb866a0ee2a60b2e1024e4a9f326 to your computer and use it in GitHub Desktop.
Calling Quala API from UnityWebRequest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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