So I'm writing a program in Unity that sends tasks to a ClickUp list. I've been able to send the request through Postman for testing properly, but whenever I try to send that request through Unity I get an error with the Json encoding:
{"err":"Unexpected token % in JSON at position 0","ECODE":"JSON_001"}
The code for the method is as follows. It's just a very basic tester method, so I know it's a little messy as is, but once I'm able to actually send the requests properly I want I'll re-write it with the full functionality.
private void SendDemoTask()
{
string jsonString = "{\"name\": \"Unity send from postman\",\"description\": \"Sent on May 24 2022\"}";
UnityWebRequest demoTaskRequest =
UnityWebRequest.Post($"https://api.clickup.com/api/v2/list/{listID}/task",jsonString);
demoTaskRequest.SetRequestHeader("Authorization",accessToken);
demoTaskRequest.SetRequestHeader("Content-Type","application/json");
var operation = demoTaskRequest.SendWebRequest();
// Wait for request to return
while (!operation.isDone)
{
CheckWebRequestStatus("Task creation failed.", demoTaskRequest);
}
Debug.Log(demoTaskRequest.result);
Debug.Log(demoTaskRequest.downloadHandler.text);
}
It seems to be an issue with the JSON encoding. Unfortunately the POST method doesn't have an argument to take a byte array. The PUT method does, but ClickUp's API won't accept the same types of requests through Put.
Is there a way for me to send this request that will correct the encoding issue? Or is the problem somewhere else?
Apologies if any part of this isn't clear. I'm fairly new to using UnityWebRequest and a total noob to webdev in general.
Thank you for any help you all can offer, I very much appreciate it!
↧