Change
$url = $apiurl . '?' . implode('&', $fields_string);
to
$url = $apiurl . '?' . implode('&', $fields_string);
You don't need to escape these ampersands since you aren't outputting them into HTML, but just feeding them straight into curl.