1 Reply Latest reply on May 9, 2016 9:58 AM by Ted Slinkard

    ASP.net C# API

    Ted Slinkard

      I am just getting started using the API.  perhaps I am doing something wrong.  I am making the call correctly but the xml I get back is invalid.


      The responsebody is (values are x out but the rest is exactly what I get returned.  notice the \ before the values.  in postman I don't get these so I assume it's something I am doing wrong.


      <?xml version='1.0' encoding='UTF-8'?><tsResponse xmlns=\"http://tableau.com/api\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://tableau.com/api http://tableau.com/api/ts-api-2.2.xsd\">

      <credentials token=\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx\">

      <site id=\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\" contentUrl=\"\" />

      <user id=\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\" />





      my code is


      public async Task<string> AdminLogin()
                  string token = "";
                  string siteid = "";

                  using (var client = new System.Net.Http.HttpClient())
                          client.BaseAddress = _baseTableauAddress;
                         client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/xml"));


                          var content = new StringContent("<tsRequest><credentials name = '" + Adminusername + "' password = '" + Adminpw + "' ><site contentUrl = '" + Site + "'/></credentials></tsRequest> ",Encoding.UTF8,"text/xml");
                          var response = client.PostAsync("/api/2.2/auth/signin", content).Result;

                          string responseBody = await response.Content.ReadAsStringAsync();

                      catch (Exception ex)
                          string t = ex.ToString();
                  return "";

        • 1. Re: ASP.net C# API
          Ted Slinkard

          Ok.  I think I have it.  I'm just used to working with json data.  (I really wish they would allow json)

          just loading it into a xmlDocument worked

          XmlDocument xdoc = new XmlDocument();


                              XmlNodeList xl= xdoc.GetElementsByTagName("credentials");

                              token = xl[0].Attributes["token"].Value;

                              siteid = xl[0].ChildNodes[0].Attributes["id"].Value;

                              string userid = xl[0].ChildNodes[1].Attributes["id"].Value;