How to set Jira subject from a variable

Hi,
I have this working httpClient request which creates a Jira ticket.

using (var httpClient = new HttpClient())
{
    using (var request = new HttpRequestMessage(new HttpMethod("POST"), restUrl))
    {
        request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64Credentials}");
        request.Content = new StringContent("{\"fields\":{\"project\":{\"id\":\"23100\",\"key\":\"Type\",\"name\":\"Ticket Type\"},\"summary\":\"Sample Subject\",\"issuetype\":{\"name\":\"Type Ticket\"},\"components\":[{\"name\":\"Test Name\"}],\"customfield_18563\":\"version\",\"customfield_18962\":{\"name\":\"location\"}}}");
        request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
        HttpResponseMessage response = await httpClient.SendAsync(request);
        string responseBody = await response.Content.ReadAsStringAsync();
        Console.WriteLine("Response: {0}", responseBody);
    }
}

However, if I try to this string so the subject comes from a variable I get the error: “Failed to update transition. Status code: BadRequest”

Response: {“errorMessages”:,“errors”:{“summary”:“Field ‘summary’ cannot be set. It is not on the appropriate screen, or unknown.”,“customfield_18563”:“Field ‘customfield_18563’ cannot be set. It is not on the appropriate screen, or unknown.”,“components”:“Field ‘components’ cannot be set. It is not on the appropriate screen, or unknown.”,“customfield_18962”:“Field ‘customfield_18962’ cannot be set. It is not on the appropriate screen, or unknown.”}}

String mysubject = "Test Subject";
request.Content = new StringContent("{\"fields\":{\"project\":{\"id\":\"23100\",\"key\":\"PPD\",\"name\":\"PPD Ticket\"},\"summary\":" + mysubject + ,\"issuetype\":{\"name\":\"PPD Ticket\"},\"components\":[{\"name\":\"Product\"}],\"customfield_18563\":\"1.0.0\",\"customfield_19129\":\"[http://jira\](http://dev-jira\)",\"customfield_18962\":{\"name\":\"text info\"}}}");

Looks like you are missing the closing double quotes after the mysubject variable.

mysubject + ,\"issuetype\"

should probably be

mysubject + "\",\"issuetype\"

The same error. I also added a " before the variable. If I Console.Writeline my string with the actual text in line and the variable they look the same.

1: {“fields”:{“project”:{“id”:“23100”,“key”:“PPD”,“name”:“PPD - Deployment”},“summary”:“Test with real text”,“issuetype”:{“name”:“PPD Ticket”},“components”:[{“name”:“Test”}],“customfield_18563”:“1.0.0”,“customfield_19129”:“http://test-jira”,“customfield_18962”:{“name”:“Location”}}}

2: {“fields”:{“project”:{“id”:“23100”,“key”:“PPD”,“name”:“PPD - Deployment”},“summary”:“Test with variables”,“issuetype”:{“name”:“PPD Ticket”},“components”:[{“name”:“Test”}],“customfield_18563”:“1.0.0”,“customfield_19129”:“http://test-jira”,“customfield_18962”:{“name”:“Location”}}}