Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending multiple arguments to triggered Azure webjos

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?

like image 867
erincerol Avatar asked Feb 06 '23 23:02

erincerol


2 Answers

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(""));
}
like image 196
Stig Stavik Avatar answered Feb 09 '23 14:02

Stig Stavik


Arguments should be space separated: string arguments = "arg1 arg2 arg3";

like image 41
Attila Cseh Avatar answered Feb 09 '23 13:02

Attila Cseh