I want to pass apikey and url instead of username and password, to connect watson assistant with my webpage.
// Encode json data
$json = json_encode($data, JSON_UNESCAPED_UNICODE);
// Post the json to Watson Assistant API via cURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://gateway.watsonplatform.net/assistant/api/v1/workspaces/'.$workspace_id.'/message?version='.$release_date); //
curl_setopt($ch, CURLOPT_USERPWD, $username.":".$password); // Set cURL Watson
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = trim(curl_exec($ch));
curl_close($ch); // Close
echo json_encode($result, JSON_UNESCAPED_UNICODE); // Send response
}
Here i would like to replace username and password with corresponded Apikey and url .