This doesn't seem to happen when creating a custom field, but it does when I am creating the custom field options.
{"options":[{"value":"value 0","disabled":false},{"value":"value 1","disabled":false},{"value":"value 2","disabled":false},{"value":"value 3","disabled":false},{"value":"value 4","disabled":false},{"value":"value 5","disabled":false},{"value":"value 6","disabled":false},{"value":"value 7","disabled":false},{"value":"value 8","disabled":false},{"value":"value 9","disabled":false}]}
Uploading via postman has no issues, however there is some conversion issue with uploading the same values through WebClient as either UTF-8 or ASCII.
It seems like the JIRA API cant reconstruct the bytes, and assumes its a foreign media type.
Here is my code:
WebClient client = new WebClient();
string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("<user>" + ":" + "<token>"));
client.Headers[HttpRequestHeader.Authorization] = string.Format("Basic {0}", credentials);
client.Headers.Set("Content-Type", "application/json");
client.Headers.Set("Accept", "application/json");
////////////////////////////////////////////
Here I upload the new Custom Field, and retrieve its context (Working)
///////////////////////////////////////////
//now that we have the context, it is time to update the options
//Creating a whole bunch of option values from 0-9
dynamic optionsObj = new JObject();
dynamic optionsArr = new JArray();
for (int i = 0; i < 10; i++) {
dynamic j = new JObject();
j.value = $"value {i}";
j.disabled = false;
optionsArr.Add(j);
}
optionsObj.options = optionsArr;
string oString = JsonConvert.SerializeObject(optionsObj, Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
dynamic oObj = JToken.Parse(oString);
string oObjstring = JsonConvert.SerializeObject(oObj, Formatting.None, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
Console.WriteLine("\n Options to be sent: \n");
Console.WriteLine(oObjstring);
Console.WriteLine();
//var stringContent = new System.Net.Http.StStringContent(json, UnicodeEncoding.UTF8, "application/json");
byte[] oObjByte = Encoding.ASCII.GetBytes(oString);
string uploadOp = $"https://<name>.atlassian.net/rest/api/2/field/{jCreated.id}/context/{Contextid}/option";
//byte[] responseArray2 = client.UploadData(uploadOp, oObjByte);
string responseText = client.UploadString(uploadOp, oObjstring);
string returned2 = Encoding.ASCII.GetString(responseArray);
Console.WriteLine(returned2);
Console.ReadLine();