I tried a few different ways I can’t get pipelineId to post (receive 400), see code below:
{
client.BaseAddress = new Uri(_serviceConfig.DataGapsBaseUrl);
var request = new HttpRequestMessage(HttpMethod.Post, "/piper/jobs");
var jsonContent = new StringContent(JsonConvert.SerializeObject(new
{
pipelineId = _serviceConfig.DataPipelineId
}), Encoding.UTF8, "application/json");
request.Content = jsonContent;
var token = await GetToken();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.ToString());
var result = await client.SendAsync(request);
var json = JsonConvert.DeserializeObject<JToken>(result.Content.ReadAsStringAsync().Result);
var jobId = json["id"].ToString();
return jobId;
}
}
When I use Postman same actions as above, I get 200 status and results:
3
Answers
Sorry Guys, my fault I need to send this:
{"pipelineId":"zxxzxzxzxz18","inputs":{"Batch_Id":9999}}
Needed to figure out how to hand double quotes and it fixed the issue.
since you are using async await , use it everywhere and this syntax is more usuall
For starters:
Change the following using await aswell to prevent thread-locking
Please note if your client is a singleton and you are setting authentication from an async context it might be overwritten by another call either recreate client or perhaps set the authorization on the HttpRequestMessage: