05-27-2016 01:39 AM
Hi Gurus, I tried using the PHP sample code and it returned a blank response. I've searched the forum and found a few people have the same issue as me but no working solution was provided. Here's the thread that closely described my problems.
Fail to forward request:Please call XMLAPI via SSL(HTTPS)
I'd appreciate it if you can help take a look into what's wrong with the code. Thanks.
Code:
-----------
<html>
<head>
<title>Create WebEx meetings via XML API</title>
</head>
<body>
<?php
// Specify WebEx site and port
$XML_SITE="[companyname].webex.com";
$XML_PORT="443";
// Build XML request document
$d["XML"] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$d["XML"] .= "<serv:message xmlns:xsi=\"https://www.w3.org/2001/XMLSchemainstance\"";
$d["XML"] .= "xmlns:serv=\"https://www.webex.com/schemas/2002/06/service\"";
$d["XML"] .= "xsi:schemaLocation=\"https://www.webex.com/schemas/2002/06/service";
$d["XML"] .= "https://www.webex.com/schemas/2002/06/service/service.xsd\">";
$d["XML"].= "<header>";
$d["XML"].= "<securityContext>";
$d["XML"].= "<webExID>[MyID]</webExID>";
$d["XML"].= "<password>[Mypassword]</password>";
$d["XML"].= "<siteName>[companyname]</siteName>";
// Set meeting starts
$d["XML"].= "<accessControl>";
$d["XML"].= "<meetingPassword>1q2w3e4r</meetingPassword>";
$d["XML"].= "</accessControl>";
$d["XML"].= "<metaData>";
$d["XML"].= "<confName>My First WebEx</confName>";
$d["XML"].= "<agenda>For testing purposes</agenda>";
$d["XML"].= " </metaData>";
$d["XML"].= "<enableOptions>";
$d["XML"].= "<chat>0</chat>";
$d["XML"].= "</enableOptions>";
$d["XML"].= "<participants>";
$d["XML"].= "<maxUserNumber>4</maxUserNumber>";
$d["XML"].= "<attendees>";
$d["XML"].= "<attendee>";
$d["XML"].= "<person>";
$d["XML"].= "<name>[Name here]</name>";
$d["XML"].= "<email>[email here]</email>";
$d["XML"].= "</person>";
$d["XML"].= "</attendee>";
$d["XML"].= "</attendees>";
$d["XML"].= "</participants>";
$d["XML"].= "<schedule>";
$d["XML"].= "<startDate>05/27/2016 17:00:00</startDate>";
$d["XML"].= "<timeZoneID>45</timeZoneID>";
$d["XML"].= "<openTime>900</openTime>";
$d["XML"].= "</schedule>";
// Meeting settings ends
$d["XML"].= "</bodyContent>";
$d["XML"].= "</body>";
$d["XML"].= "</serv:message>";
$URL = "https://{$XML_SITE}/WBXService/XMLService";
$Result = postIt($d,$URL,$XML_PORT);
exit;
//
// postIt()
//
// POSTs the XML action document and calling user variables
// to the specified WebEx XML Server and receives an XML response document
//
function postIt($DataStream, $URL, $Port)
{
// Strip http:// from the URL if present
$URL = ereg_replace("^https://", "", $URL);
echo $URL;
// Separate into Host and URI
$Host = substr($URL, 0, strpos($URL, "/"));
$URI = strstr($URL, "/");
// Form the request body
$reqBody = "";
while (list($key, $val) = each($DataStream)) {
if ($reqBody) $reqBody.= "&";
$reqBody.= $key."=".urlencode($val);
}
$ContentLength = strlen($reqBody);
$xml = $DataStream['XML'];
// Generate the request header
global $Debug_Mode;
$Debug_Mode = 1;
$URL = $Host;
$fp = fsockopen($URL,$Port,$errno,$errstr);
$Post = "POST /WBXService/XMLService HTTP/1.0\n";
$Post .= "Host: $URL\n";
$Post .= "Content-Type: application/application/x-www-form-urlencoded\n";
$Post .= "Content-Length: ".strlen($xml)."\n\n";
$Post .= "$xml\n";
if($Debug_Mode){
echo "<hr>XML Sent:<br><textarea cols=\"50\" rows=\"25\">".htmlspecialchars($xml)."</textarea><hr>";
}
if($fp){
fwrite($fp,$Post);
$response = "";
while (!feof($fp)) {
$response .= fgets($fp, 1024);
}
if($Debug_Mode){
echo "<br>XML Received:<br><textarea cols=\"50\" rows=\"25\">".htmlspecialchars($response)."</textarea><hr>";
}
return $response;
}
else{
echo "$errstr ($errno)<br />\n";
return false;
}
}
?>
</body>
</html>
Solved! Go to Solution.
06-02-2016 02:13 PM
Greetings! As you've noticed, the php sample code is outdated and does not work correctly. The following example (also attached) does work, and should provide you with a good idea of how to write PHP code to interact with our XML API:
<?php header("Content-Type: text/xml"); $sitename = "apidemoeu"; //Sitename is the subdomain of a WebEx URL. ex: sitename for https://apidemoeu.webex.com is apidemoeu $username = "username"; $password = "password"; $XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; $XML .="<serv:message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"; $XML .=" <header>"; $XML .=" <securityContext>"; $XML .=" <webExID>$username</webExID>"; $XML .=" <password>$password</password>"; $XML .=" <siteName>$sitename</siteName>"; $XML .=" <returnAdditionalInfo>TRUE</returnAdditionalInfo>"; $XML .=" </securityContext>"; $XML .=" </header>"; $XML .=" <body>"; $XML .=" <bodyContent xsi:type=\"java:com.webex.service.binding.site.GetSite\">"; $XML .=" </bodyContent>"; $XML .=" </body>"; $XML .="</serv:message>"; $request = stream_context_create(array("http"=>array("method"=>"POST","header"=>"Content-Type:text/xml","content"=>$XML))); $response = file_get_contents("https://$sitename.webex.com/WBXService/XMLService", false, $request); echo $response; ?>
06-02-2016 02:13 PM
Greetings! As you've noticed, the php sample code is outdated and does not work correctly. The following example (also attached) does work, and should provide you with a good idea of how to write PHP code to interact with our XML API:
<?php header("Content-Type: text/xml"); $sitename = "apidemoeu"; //Sitename is the subdomain of a WebEx URL. ex: sitename for https://apidemoeu.webex.com is apidemoeu $username = "username"; $password = "password"; $XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; $XML .="<serv:message xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"; $XML .=" <header>"; $XML .=" <securityContext>"; $XML .=" <webExID>$username</webExID>"; $XML .=" <password>$password</password>"; $XML .=" <siteName>$sitename</siteName>"; $XML .=" <returnAdditionalInfo>TRUE</returnAdditionalInfo>"; $XML .=" </securityContext>"; $XML .=" </header>"; $XML .=" <body>"; $XML .=" <bodyContent xsi:type=\"java:com.webex.service.binding.site.GetSite\">"; $XML .=" </bodyContent>"; $XML .=" </body>"; $XML .="</serv:message>"; $request = stream_context_create(array("http"=>array("method"=>"POST","header"=>"Content-Type:text/xml","content"=>$XML))); $response = file_get_contents("https://$sitename.webex.com/WBXService/XMLService", false, $request); echo $response; ?>
06-03-2016 02:17 AM
Thanks Michael. This is really helpful.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide