Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible with API v2 #13

Open
jankap opened this issue Apr 12, 2021 · 7 comments
Open

Incompatible with API v2 #13

jankap opened this issue Apr 12, 2021 · 7 comments

Comments

@jankap
Copy link

jankap commented Apr 12, 2021

Thank you very much for this great tool! However, I upgraded my docker container to v2 and it seems that the API is incompatible. Are there any plans to migrate to API v2 or do you know if the old one is fully functional still?
https://docs.influxdata.com/influxdb/v2.0/api/

Thanks!

@EnricSala
Copy link
Owner

Hi @jankap,

Could you provide more details about the incompatibilities that you are facing?

According to the docs, both /query and /write endpoints should be compatible with v1:
https://docs.influxdata.com/influxdb/v2.0/reference/api/influxdb-1x/

However, I am hitting HTTP 401 Unauthorized errors when running the tests with v2:

Error occurred in InfluxDbTest/basic_write_and_read and it did not run to completion.
    ---------
    Error ID:
    ---------
    'MATLAB:webservices:HTTP401StatusCodeError'
    --------------
    Error Details:
    --------------
    Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray
    (line 373)
    The server returned the status 401 with message "" in response to the
    request to URL http://localhost:8086/query.
    
    Error in readContentFromWebService (line 46)
            byteArray = copyContentToByteArray(connection);
    
    Error in webwrite (line 139)
        [varargout{1:nargout}] = readContentFromWebService(connection, options);
    
    Error in InfluxDB/runCommand (line 133)
                    response = webwrite(url, params{:}, opts);

    Error in InfluxDbTest/beforeEach (line 16)
                test.Client.runCommand(['CREATE DATABASE "', test.Database,
                '"'], true);

Is this similar to the problem that you are having?

@Sp0b1e
Copy link

Sp0b1e commented Apr 15, 2021

Hi @EnricSala,

I am also trying to access V2 of the API from matlab right now.

I have the same problem regarding the access.

Error using matlab.internal.webservices.HTTPConnector/copyContentToByteArray (line 373)
The server returned the status 401 with message "" in response to the request to URL
http://myip:myport/query?q=SHOW+DATABASES.

Error in readContentFromWebService (line 46)
        byteArray = copyContentToByteArray(connection);

Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);

Error in InfluxDB/runCommand (line 136)
                response = webread(url, params{:}, opts);

Error in InfluxDB/databases (line 46)
            result = obj.runCommand('SHOW DATABASES');

Error in TEST (line 15)
dbs = influxdb.databases()

I think the problem is because the API V2 uses tokens for authentication.

@jankap
Copy link
Author

jankap commented Apr 15, 2021

The token issue can be solved approx. like this:

            opts = weboptions();
            opts.HeaderFields = ["Authorization","Token <myTokenFromWebinterface>"];
           
            % api v2
            url = obj.Url + "api/v2/";

            % api v1, influxDb version >= 2
            url = [obj.Url '/query'];    
           

            if requiresPost
                opts.Timeout = obj.WriteTimeout;
                response = webwrite(url, params{:}, opts);
            else
                opts.Timeout = obj.ReadTimeout;
                response = webread(url, params{:}, opts);
            end

This is part of InfluxDB.m.

However, even with api v1 endpoint CREATE DATABASE does not work (first test in run_tests.m fails).

@Sp0b1e
Copy link

Sp0b1e commented Apr 15, 2021

Thanks, @jankap.

Can you tell me where in the Influxdb.m i have to put this?

@EnricSala can you maybe update the Influxdb.m to accept the token directly in the constructor?

According to the docs, both /query and /write endpoints should be compatible with v1:
https://docs.influxdata.com/influxdb/v2.0/reference/api/influxdb-1x/

Have you already tried this? At the moment reading from and writing in a existing Database would be fine for me.

@EnricSala
Copy link
Owner

EnricSala commented Apr 15, 2021

The compatibility API supports InfluxQL, with the following caveats, InfluxQL database management commands are not supported.

@jankap ah it seems I had missed this ^ from the docs.
That's unfortunate becase it will require changes to use the new APIs from v2.

@EnricSala can you maybe update the Influxdb.m to accept the token directly in the constructor?

@Sp0b1e That's tricky because the library should continue to support v1 users, which at this time is still probably most of them. Will see if I can find some time in the coming week to take a look at this :)

@SaadArshad222
Copy link

The compatibility API supports InfluxQL, with the following caveats, InfluxQL database management commands are not supported.

@jankap ah it seems I had missed this ^ from the docs.
That's unfortunate becase it will require changes to use the new APIs from v2.

@EnricSala can you maybe update the Influxdb.m to accept the token directly in the constructor?

@Sp0b1e That's tricky because the library should continue to support v1 users, which at this time is still probably most of them. Will see if I can find some time in the coming week to take a look at this :)

@EnricSala I just started using Influxdb V2 and was having the same 401 error as the others have explained above. Just was wanted to check if you've come up with a fix for it yet?

@EnricSala
Copy link
Owner

Hi @SaadArshad222, unfortunately I haven't been able to make much progress on this topic as I am quite busy at the moment. Will post a status update when there are new :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants