2019-07-27 11:46


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 .

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongtanxi5676756 dongtanxi5676756 2年前

    Please try this. Instead of username, use the keyword "apikey" and for password use the actual API Key that you have for the service. That should work.

    点赞 评论 复制链接分享