but im trying to use klaviyo and i just cannot make it work. i have read through their api for post requests but had no luck in either using the above script or using the one i have for the leaderboard, which is this ( dont work)
private IEnumerator SendData()
{
WWWForm form = new WWWForm();
form.AddField("email", emailField.text);
form.AddField("api_key", "my api key goes here");
UnityWebRequest www = UnityWebRequest.Post("https://a.klaviyo.com/api/v2/lists?api_key=my api key", form);
// i have also tried it like this :
//UnityWebRequest.Post("https://a.klaviyo.com/api/v2/list/{LIST_ID}/subscribe
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Registered");
}
Debug.Log(emailField.text);
}
i either get a 404 or a 400 error code. now if i use the mailchimp script i get an error with the api key format
As with all network code, get it working with Postman or curl first. That makes it NOT a Unity problem. Solve the networking first. You must solve that or anything else is irrelevant.
Once you have that working, then try and port it to UnityWebRequest. If it still doesn’t work, one handy debug solution is to hook up a proxy like Charles and compare the functioning output from Postman / curl to the output from Unity, and from that reason about where your issues are.
thanks for the reply, i managed to post a request through postman and now am looking for a way to put a json string into unity so i can link it and try it out! Basiclay on postman this is the url that posts the request
well im looking into it! found some threads here doing that but yeah i still need to fully understand it and try it out! unless you have a general idea and would be willing to help once more!!
im going to try once more in case someone can help! i got to a point i can make my string to json so i tried posting it but i still get the 400 error!
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class MailingScript : MonoBehaviour
{
public InputField emailText;
[Serializable]
public class Profile
{
public string email;
}
[Serializable]
public class MyClass
{
public Profile[] profiles;
}
IEnumerator SaveData()
{
MyClass myClass = new MyClass();
myClass.profiles = new Profile[1];
myClass.profiles[0] = new Profile();
myClass.profiles[0].email = emailText.text;
string json = JsonUtility.ToJson(myClass.profiles[0]);
UnityWebRequest www = UnityWebRequest.Post("https://a.klaviyo.com/api/v2/list/YeXzKp/members?api_key=pk_ec448e1bdab7504c143466ca5eeabc5e95&profiles=[]", json);
www.SetRequestHeader("content-type", "application/json");
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error);
}
else
{
Debug.Log("Form upload complete!");
}
Debug.Log(json);
}
public void Subscribe()
{
StartCoroutine(SaveData());
}
}