Using API for scripting

Hello,

I am trying to use the REST API for executing a script.
referring here - https://sites.google.com/a/webpagetest.org/docs/advanced-features/webpagetest-restful-apis

however there are no examples for this.
I have a multiline script which I need to execute using the rest api.

It is just like any other parameter. script=

You need to make sure you are url-encoding all of your API parameters if you are passing them in the URL. Most of them won’t really change but the test URL and script can often have characters that MUST be encoded.

I am new to this.

I tried several ways to put my script (which actually do login for me) into the URL but all my efforts are in vain.

Can you please help me with one example?

http://www.webpagetest.org/runtest.php?&runs=1&f=json&url=https://beta-xxxxxxxxxxxxxx.ccccom? setValue id=username someuser@aol.com setValue id=password somepassword submitForm name=AOLLoginForm&k=A.c99e36xxxxxxxxxxx679c500410f

You need to urlencode the script and pass it as script=xxxxxxx.

Mostly likely that’s the issue for the OP, that being said, for me this error is being thrown if script starts with anything else than ‘navigate’, e.g.

<?php

$query = [
  'k' => 'MY_KEY',
  'location' => 'Prague:Chrome.Cable',
  'f' => 'json',
  'fvonly' => '1',
  'private' => '1',
  'video' => '0',
  'noopt' => '1',
  'noheaders' => '1',
  'pngss' => '1',
  'ignoreSSL' => '1',
  'script' => 'navigate https://domain.cz/login setValue id=userNameInput USERNAME setValue id=passwordInput PASSWORD clickAndWait id=submitButton navigate https://domain.cz/page1 navigate https://domain.cz/page2'
];

$query['script'] = str_replace(' ', "\t", $query['script']);

echo 'http://www.webpagetest.org/runtest.php?'. http_build_query($query) . PHP_EOL;
?>

The script above which worked perfectly via UI is:

logData    0
navigate    https://domain.cz/login
logData    1
setValue    id=userNameInput    USERNAME
setValue    id=passwordInput   PASSWORD
clickAndWait    id=submitButton
navigate    https://domain.cz/page1
navigate    https://domain.cz/page2

I get the OP`s error if I start my script with logData, it works however if I start with navigate.

Still playing around as I get the job accepted but it looks that script part of logging in does not work, just the first line of navigate aka going to right URL to start with.