Webtrends API authentication PHP
Asked Answered
B

2

6

I am trying to connect to Webtrend's API using PHP but haven't been able to authenticate.

The example given on the WT's documentation is for .NET or Ruby, the .Net example is like this:

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 that WebClient class on PHP?

I have been trying to authenticate using CURL using

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

but so far no luck. I get an error message saying that the parameters are not correct.

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 no luck so far.

Babs answered 16/5, 2011 at 7:39 Comment(4)
show details of your php scriptDoorjamb
i fixed the problem. after looking at the error message in the http headers ('SSL certificate problem, verify that the CA cert is OK') I added these lines to the code and now it works:Babs
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);Babs
Would be much easier with PHP.NET https://mcmap.net/q/1059526/-is-there-a-possibility-of-there-ever-being-a-php-net/78782Luigi
L
0

@Kevin Horst provided a good example of executing a basic authentication request with curl and PHP. I often need to do this via the command line. To do this you need curl installed on 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 documentation on the WebTrends Data Extraction API. They use Basic Authentication over SSL which is a standard for RESTful authentication.

WebTrends Data extraction API

Last answered 11/7, 2011 at 10:4 Comment(0)
S
1

I think you have to 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); 
Scibert answered 16/5, 2011 at 7:39 Comment(0)
L
0

@Kevin Horst provided a good example of executing a basic authentication request with curl and PHP. I often need to do this via the command line. To do this you need curl installed on 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 documentation on the WebTrends Data Extraction API. They use Basic Authentication over SSL which is a standard for RESTful authentication.

WebTrends Data extraction API

Last answered 11/7, 2011 at 10:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.