cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1191
Views
2
Helpful
3
Replies

How to get list meeting using URL API (WBS31) by ASP.NET(C#)

atiwat.s1
Level 1
Level 1

Hello,Guy.

Could you help me,please?

i am a new developer for cisco webex.I would like to get a meeting list by url api(wbs31).i login success and webex return CSRF parameter.

this is my code as below.

using System;

using System.Collections.Generic;

using System.Collections.Specialized;

using System.Drawing.Text;

using System.IO;

using System.Net;

using System.Net.Cache;

using System.Text;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class Test_httpPostPage : System.Web.UI.Page

{

    private string WEBEX_SITE = "https://mywebex.webex.com/mywebexonline";

    private string WEBEX_USER = "myuser", WEBEX_PASS = "pass123";

    private string CURRENT_URL = "";

    private CookieContainer cookieContainer = new CookieContainer();

    protected void Page_Load(object sender, EventArgs e)

    {

        try

        {

            CURRENT_URL = HttpContext.Current.Request.Url.AbsoluteUri;

            if (CURRENT_URL.IndexOf("?") > 0)

            {

                CURRENT_URL = CURRENT_URL.Substring(0, CURRENT_URL.IndexOf("?"));

            }

                      

            doListMeetingAPI();          

        }

        catch (Exception ex)

        {

            Response.Write("<br/>Err : " + ex.Message);

            Response.Write("<br/>StackTrace : " + ex.StackTrace);

        }

    }

    private void doListMeetingAPI()

    {

        try

        {         

            string result = "", csrfToken = "";

            result = callLoginAPI(WEBEX_USER, WEBEX_PASS).Trim();          

            csrfToken = parseCSRFToken(result);

            if (csrfToken == null || csrfToken.Equals(""))

            {

                csrfToken = "";

            }

          

            ///List Meeting

            result = "";

            result = callListMeetingAPI(WEBEX_SITE, csrfToken);          

            Response.Write("<br/>callListMeetingAPI : Data : " + result.Trim());

        }

        catch (Exception ex)

        {

            Response.Write("<br/>Err : " + ex.Message);

            Response.Write("<br/>StackTrace : " + ex.StackTrace);

        }

    }

    private string callLoginAPI(string userName, string password)

    {

        try

        {          

            string backUrl = CURRENT_URL;

            if (backUrl.IndexOf("?") > 0)

            {

                backUrl = backUrl.Substring(0, backUrl.IndexOf("?"));

            }

            backUrl = HttpUtility.UrlEncode(backUrl);

            string loginAPI = WEBEX_SITE + "/p.php";

            string result = "";

            string _params = "";

            _params += "AT=LI";

            _params += "&WID=" + userName;

            _params += "&PW=" + password;

            _params += "&MU=GoBack";

            _params += "&BU=" + backUrl;

            result = executePostCommand(loginAPI, _params);

            return result;

        }

        catch (Exception ex)

        {

            throw;

        }

    }

   

    private string callListMeetingAPI(object site, string csrfToken)

    {

        try

        {

            string backUrl = CURRENT_URL;

            if (backUrl.IndexOf("?") > 0)

            {

                backUrl = backUrl.Substring(0, backUrl.IndexOf("?"));

            }

            backUrl = HttpUtility.UrlEncode(backUrl);

            string listMeetingAPI = site + "/m.php";

            string result = "";

            string _params = "";

            _params += "AT=LM";

            _params += "&CSRF=" + csrfToken;

            _params += "&MU=GoBack";

            _params += "&BU=" + backUrl;

            _params = _params.Replace("&CSRF=&CSRF=", "&CSRF=");

            result = executePostCommand(listMeetingAPI,_params).ToString();

            return result;

        }

        catch (Exception ex)

        {

            throw;

        }

    }

       

    private string executePostCommand(string siteUrl, string _params)

    {

        try

        {          

            string result = "";

            HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Default);

            HttpWebRequest.DefaultCachePolicy = policy;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(siteUrl);

            request.CookieContainer = cookieContainer;

            request.CachePolicy = policy;

            request.Credentials = CredentialCache.DefaultCredentials;

            request.Method = "POST";

            // Create POST data and convert it to a byte array.

            string postData = _params;

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);

            request.ContentType = "application/x-www-form-urlencoded";

            request.ContentLength = byteArray.Length;

            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);

            dataStream.Close();

            // Get the response.

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            dataStream = response.GetResponseStream();

            StreamReader reader = new StreamReader(dataStream);

            result = reader.ReadToEnd().Trim();

          

            reader.Close();           

            dataStream.Close();

            response.Close();

            return result;

        }

        catch (Exception ex)

        {

            return "";

        }

    }

    private string parseCSRFToken(string responseAsString)

    {

        string csrfToken = "";

        string findKey = "&CSRF=";

        if (!responseAsString.Equals(""))

        {

            responseAsString = responseAsString.Replace("\\x3a", ":").Replace("\\x2f", "/").Replace("\\x3f", "?").Replace("\\x3d", "=").Replace("\\x26", "&");

            int startIndex = responseAsString.ToString().IndexOf(findKey);

            string responseSplitKey = responseAsString.Substring(startIndex);

            int endIndex = responseSplitKey.IndexOf("\";");

            string responseSplitVal = responseSplitKey.Substring(0, endIndex);

            if (!responseSplitVal.Equals(""))

            {

                csrfToken = responseSplitVal;

            }

        }

        return csrfToken;

    }

}

================== Result =====================

step 1 : callLoginAPI

-

<html>

<head>

       <title> </title>

       <meta http-equiv="content-type" content="text/html; charset=UTF-8">

<meta name="description" content="270"><link rel="shortcut icon" href="https://community.cisco.com/favicont29.ico" type="image/x-icon">

</head>

<body>

<form id="commonGet2PostForm"></form>

<script src="/cmp3100/webcomponents/html/js/commonGet2Post.js"></script>

<script language="JavaScript">

var url = "http\x3a\x2f\x2flocalhost\x3a58901\x2fTest\x2fhttpPostPage.aspx\x3fAT\x3dLI\x26WID\x3dmyuser\x26ST\x3dSUCCESS\x26CSRF\x3dba5822b3-cd8e-471e-8884-eee115e70294";

location.href=url;

</script>

</body>

</html>

Step 2 : get CSRF from resute

- CSRF = a5822b3-cd8e-471e-8884-eee115e70294


Step 3 : Call callListMeetingAPI

- result :

<html>

<head>

       <title> </title>

       <meta http-equiv="content-type" content="text/html; charset=UTF-8">

<meta name="description" content="1"><link rel="shortcut icon" href="https://community.cisco.com/favicont29.ico" type="image/x-icon">

</head>

<body>

<form id="commonGet2PostForm"></form>

<script src="/cmp3100/webcomponents/html/js/commonGet2Post.js"></script>

<script language="JavaScript">

var url = "http\x3a\x2f\x2flocalhost\x3a58901\x2fTest\x2fhttpPostPage.aspx\x3fAT\x3dLM\x26ST\x3dFAIL\x26RS\x3dAccessDenied";

location.href=url;

</script>

</body>

</html>

Thank you so much

Atiwat

3 Replies 3

ryanhunt
Level 5
Level 5

We urge all new development to use the XML API over the URL API, we have code examples for exactly what your trying to do with the XML API avilable here:

https://developer.cisco.com/site/webex-developer/develop-test/xml-api/sample-code/

Thank you so much for advise, Ryan Hunt.

Is possible if i give the URL API example code from you?.Because our site use the URL API.I was assigned to fix and develop.

We do not provide code examples for the URL API..

It appears as if you are not appending the CSRF token to your request.