How to get superuser token_auth


#1

Hello,
I am trying to use API SitesManager.addSite but I get the following error:

In my get request I specify auth_token of a user that is not the superuser. The superuser details are in config.ini.php and there is no token for this user.

My url looks like this:

http://localhost:8888/piwik?module=API&method=SitesManager.addSite&siteName=MySiteName&urls=http://localhost:8888/site1/&token_auth=1e390d9ac5f90580f0c0f578362747bd

How can I overcome this error?


(Matthieu Aubry) #2

the URL parameter should be URL Encoded: URL Decoder/Encoder


#3

Thank you for your answer.

I encode my URL but I couldn’t solve my problem.
What authentication should I provide in my URL?

Normal Piwik users cannot add sites. I need to be superuser.
If I use token_auth=somePiwikUserToken then I get

How can I call this API with superuser access?

Here is my code:

QueryString qs = new QueryString(“module”, “API”);
qs.add(“method”, “SitesManager.addSite”);
qs.add(“siteName”, “Site1”);
qs.add(“urls”, “http://aspv3flex.zone-secure.net/555/publications/”);

String urlString = "http://localhost:8888/piwik?" + qs;
URL url = new URL(urlString);

static class QueryString {
private String query = “”;
public QueryString(String name, String value) {
encode(name, value);
}
public void add(String name, String value) {
query += “&”;
encode(name, value);
}
private void encode(String name, String value) {
try {
query += URLEncoder.encode(name, “UTF-8”);
query += “=”;
query += URLEncoder.encode(value, “UTF-8”);
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException(“Broken VM does not support UTF-8”);
}
}


#4

I have solved my problem. I found the superuser token_auth.
Login with superuser and go to API page. There you can find the token_auth for the user you have logged in with.


(Matthieu Aubry) #5

What is the token_auth and where can I find this token to use in the API calls?