Webtrends API Authentication

I am trying to connect to the Webtrend API using PHP, but could not authenticate.

The example provided in the WT documentation is for .NET or Ruby, the .Net example is as follows:

var svc = new WebClient(); svc.Credentials = new NetworkCredential("yourWebTrendsAccount\WebTrendsUserName", "yourSuperSecretPassword"); svc.DownloadStringCompleted += svc_DownloadStringCompleted; svc.DownloadStringAsync(new Uri(baseUri)); 

I am not familiar with .NET, but is there an equivalent of this WebClient class in PHP?

I am trying to authenticate using CURL using

 username = "my_account_name/my_login_name" password = "my_password" 

but so far no luck. I receive an error message indicating that the parameters are incorrect.

Update: adding code

  $username=urlencode('my_account_name\my_login_name'); $password="my_password"; $postdata="username=$username&password=$password"; $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL,"https://ws.webtrends.com/v2/ReportService/profiles/XXXXXXXX/reports/XXXXXXXX/?totals=all&period=2011w14&format=xml"); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE); curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); curl_setopt ($ch, CURLOPT_POST, 1); $result = curl_exec ($ch); curl_close($ch); var_dump($result); 

I also tried

 curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); 

but so far no luck.

+6
source share
2 answers

@ Kevin Horst is a good example of doing a basic authentication request with curl and PHP. I often have to do this through the command line. To do this, you need to install curl in your system.

  curl --user username:password \ -i https://ws.webtrends.com/v2/ReportService/profiles/XXXXXXXX/reports/XXXXXXXX/?totals=all&period=2011w14&format=xml 

According to the WebTrends Data Extraction API documentation. They use basic SSL authentication, which is the standard for RESTful authentication.

WebTrends Data Removal API

0
source

I think you should use CURLOPT_USERPWD instead of postdata:

 $connection = curl_init(); curl_setopt($connection, CURLOPT_URL, 'https://ws.webtrends.com/v2/ReportService/profiles/XXXXXXXX/reports/XXXXXXXX/?totals=all&period=2011w14&format=xml'); curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1); curl_setopt($connection, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt(CURLOPT_USERPWD, sprinf('%s:%s', $username, $password)) $data = curl_exec(); curl_close($ch); 
+1
source

Source: https://habr.com/ru/post/888189/


All Articles