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
(Matthieu Aubry)
October 30, 2012, 3:11am
2
the URL parameter should be URL Encoded: URL Decoder/Encoder
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”);
}
}
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
(Matthieu Aubry)
May 24, 2014, 4:17am
5