I'm trying to send multiple arguments to azure webjob while triggering. According to this https://github.com/projectkudu/kudu/wiki/WebJobs-API#invoke-a-triggered-job,
I can call it like like:
POST /api/triggeredwebjobs/{job name}/run?arguments={arguments}
I tried several ways to add multiple arguments such as:
?arguments=1&arguments=2
?arguments[]=1&arguments[]=2
?arguments[0]=1&arguments[1]=2
?arguments={1,2}
etc, I tried several more stupid stuff and also tried using form data. None of seems to be working. My webjob is only picking up the first argument. For example when I do this:
static void Main(string[] args)
{
Console.WriteLine(args[0]);
Console.WriteLine(args[1]);
}
The first one works for above examples, but then I get an exception for second line saying index out of bounds. Is there a way to trigger webjob with multiple arguments and if so how can I achieve that?
I think the golden nugget you are looking for is:
run?arguments={arg1} {arg2}
A complete working sample would read something like this:
using (var client = new HttpClient())
{
client.BaseAddress = new Uri("https://your-app-name.scm.azurewebsites.net/");
client.DefaultRequestHeaders.Accept.Clear();
//username and password from Publish Profile, can test via https://your-app-name.scm.azurewebsites.net/basicAuth
var userName = "$your-app-name";
var password = "go30T5qqBfl0mv3wzhezrkifrKrPEw78ZieLE0JfwYEZ1yx6wy3hDgygBvbM";
var encoding = new ASCIIEncoding();
var authHeader = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(encoding.GetBytes(string.Format($"{userName}:{password}"))));
client.DefaultRequestHeaders.Authorization = authHeader;
HttpResponseMessage response = await client.PostAsync($"api/triggeredwebjobs/YourTriggeredWebJob/run?arguments={arg1} {arg2}", new StringContent(""));
}
Arguments should be space separated: string arguments = "arg1 arg2 arg3";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With