Sending GET request to API endpoint issues

I am currently working on a project to get certain values from an API and use the values to make and update tags every few seconds. My problem is that I have tried everything to send a get request to the API, but I cannot get any data from it. From troubleshooting, I think the problem has to do with the URL of the API. The common errors I have gotten are Invalid URL - no protocol, Unable to GET -URL, and a status code of 302 when I need 200. I will post my code below. Any suggestions or help is welcome. My code is relatively incomplete until I can properly read the json data to write to tags.

import system

# API for KE2Evap
def getKE2EvapAPI():
    client = system.net.httpClient()
    url = "http://URL-IPaddress/api/Status"
    response = client.get(url)  # Make a request to the KE2 Evap OEM API
   
    if response.good:
        KE2APIValue = response.json  # Extract the value from the API response
        return KE2APIValue  # Return the API value
    else:
		print("Unable to get API value")
		return None
        

# Function for writing API value to tag
def writeValueToTag(tag_path, value):
    system.tag.write(tag_path, value)
      
	  
#Function to update tags with values from API
def updateTags():
    tag_mappings = {
        "[default]_types_/KE2 EVAP OEM API/FramewareVersion": "current", 	#test tag path and api argument key
     
        # Add more tag paths and their corresponding API argument keys as needed - added once program is working
    }

    KE2APIValue = getKE2EvapAPI()
    if KE2APIValue is not None: 	#if value != null
        for tag_path, api_key in tag_mappings.items():
            value_to_write = KE2APIValue.get(api_key) #get value from get request
            if value_to_write is not None:
                writeValueToTag(tag_path, value_to_write) #Function call to write values to tags
            else:
                print("API key not found in the API response for tag", tag_path)
    else:
        print("Failed to get KE2 Evap OEM API value")

updateTags()

{ Pssst! Your code is unreadable. Please edit your post--the pencil icon--and highlight all of the code you pasted. Then click the "preformatted text" button--looks like </>--so that the forum knows to show it properly. }

Thanks, should work now

Full error / stack trace or any additional info you have from the current revision of the code would be useful. Otherwise we're just guessing.

Full error:
Java Traceback:
Traceback (most recent call last):
File "", line 22, in
File "", line 6, in makeGetRequest
File "", line 6, in makeGetRequest
at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.send(JythonHttpClient.java:103)

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.get(JythonHttpClient.java:306)

at jdk.internal.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: Unable to GET https://172.19.108.30/api/Status

at org.python.core.Py.JavaError(Py.java:547)

at org.python.core.Py.JavaError(Py.java:538)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:208)

at org.python.core.PyObject.__call__(PyObject.java:477)

at org.python.core.PyObject.__call__(PyObject.java:481)

at org.python.core.PyMethod.__call__(PyMethod.java:141)

at org.python.pycode._pyx245.makeGetRequest$1(<input>:18)

at org.python.pycode._pyx245.call_function(<input>)

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyBaseCode.call(PyBaseCode.java:134)

at org.python.core.PyFunction.__call__(PyFunction.java:416)

at org.python.pycode._pyx245.f$0(<input>:27)

at org.python.pycode._pyx245.call_function(<input>)

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1687)

at org.python.core.Py.exec(Py.java:1731)

at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)

at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:611)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:599)

at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: java.io.IOException: Unable to GET https://172.19.108.30/api/Status

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.send(JythonHttpClient.java:103)

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.get(JythonHttpClient.java:306)

at jdk.internal.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

... 25 more

Caused by: java.io.IOException: No subject alternative names matching IP address 172.19.108.30 found

at java.net.http/jdk.internal.net.http.HttpClientImpl.send(Unknown Source)

at java.net.http/jdk.internal.net.http.HttpClientFacade.send(Unknown Source)

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.send(JythonHttpClient.java:101)

... 30 more

Caused by: javax.net.ssl.SSLHandshakeException: No subject alternative names matching IP address 172.19.108.30 found

at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source)

at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)

at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)

at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)

at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(Unknown Source)

at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(Unknown Source)

at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(Unknown Source)

at java.base/sun.security.ssl.SSLHandshake.consume(Unknown Source)

at java.base/sun.security.ssl.HandshakeContext.dispatch(Unknown Source)

at java.base/sun.security.ssl.SSLEngineImpl$DelegatedTask$DelegatedAction.run(Unknown Source)

at java.base/sun.security.ssl.SSLEngineImpl$DelegatedTask$DelegatedAction.run(Unknown Source)

at java.base/java.security.AccessController.doPrivileged(Native Method)

at java.base/sun.security.ssl.SSLEngineImpl$DelegatedTask.run(Unknown Source)

at java.base/java.util.ArrayList.forEach(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate.lambda$executeTasks$3(Unknown Source)

at java.net.http/jdk.internal.net.http.HttpClientImpl$DelegatingExecutor.execute(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate.executeTasks(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate.doHandshake(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader.processData(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader$ReaderDownstreamPusher.run(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SynchronizedRestartableTask.run(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(Unknown Source)

... 3 more

Caused by: java.security.cert.CertificateException: No subject alternative names matching IP address 172.19.108.30 found

at java.base/sun.security.util.HostnameChecker.matchIP(Unknown Source)

at java.base/sun.security.util.HostnameChecker.match(Unknown Source)

at java.base/sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)

at java.base/sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)

at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)

at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)

... 22 more

Traceback (most recent call last):
File "", line 22, in
File "", line 6, in makeGetRequest
File "", line 6, in makeGetRequest
at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.send(JythonHttpClient.java:103)

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.get(JythonHttpClient.java:306)

at jdk.internal.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: Unable to GET https://172.19.108.30/api/Status

('Failed to make GET request:', 'get() argument url: expected String instance, PyObjectDerived found')
Failed to retrieve data from the API

('Failed to make GET request:', 'Invalid URL - no protocol: [https://172.19.108.30/api/Status]')
Failed to retrieve data from the API

('Failed to make GET request:', 'Invalid URL - no protocol: 172.19.108.30/api/Status')
Failed to retrieve data from the API

Java Traceback:
Traceback (most recent call last):
File "", line 23, in
File "", line 7, in makeGetRequest
File "", line 7, in makeGetRequest
at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.send(JythonHttpClient.java:103)

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.get(JythonHttpClient.java:306)

at jdk.internal.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: Unable to GET https://172.19.108.30/index.htm

at org.python.core.Py.JavaError(Py.java:547)

at org.python.core.Py.JavaError(Py.java:538)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:192)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:208)

at org.python.core.PyObject.__call__(PyObject.java:477)

at org.python.core.PyObject.__call__(PyObject.java:481)

at org.python.core.PyMethod.__call__(PyMethod.java:141)

at org.python.pycode._pyx253.makeGetRequest$1(<input>:19)

at org.python.pycode._pyx253.call_function(<input>)

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyBaseCode.call(PyBaseCode.java:134)

at org.python.core.PyFunction.__call__(PyFunction.java:416)

at org.python.pycode._pyx253.f$0(<input>:28)

at org.python.pycode._pyx253.call_function(<input>)

at org.python.core.PyTableCode.call(PyTableCode.java:173)

at org.python.core.PyCode.call(PyCode.java:18)

at org.python.core.Py.runCode(Py.java:1687)

at org.python.core.Py.exec(Py.java:1731)

at org.python.util.PythonInterpreter.exec(PythonInterpreter.java:277)

at org.python.util.InteractiveInterpreter.runcode(InteractiveInterpreter.java:130)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:611)

at com.inductiveautomation.ignition.designer.gui.tools.jythonconsole.JythonConsole$ConsoleWorker.doInBackground(JythonConsole.java:599)

at java.desktop/javax.swing.SwingWorker$1.call(Unknown Source)

at java.base/java.util.concurrent.FutureTask.run(Unknown Source)

at java.desktop/javax.swing.SwingWorker.run(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at java.base/java.lang.Thread.run(Unknown Source)

Caused by: java.io.IOException: Unable to GET https://172.19.108.30/index.htm

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.send(JythonHttpClient.java:103)

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.get(JythonHttpClient.java:306)

at jdk.internal.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java:190)

... 25 more

Caused by: java.io.IOException: No subject alternative names matching IP address 172.19.108.30 found

at java.net.http/jdk.internal.net.http.HttpClientImpl.send(Unknown Source)

at java.net.http/jdk.internal.net.http.HttpClientFacade.send(Unknown Source)

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.send(JythonHttpClient.java:101)

... 30 more

Caused by: javax.net.ssl.SSLHandshakeException: No subject alternative names matching IP address 172.19.108.30 found

at java.base/sun.security.ssl.Alert.createSSLException(Unknown Source)

at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)

at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)

at java.base/sun.security.ssl.TransportContext.fatal(Unknown Source)

at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(Unknown Source)

at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(Unknown Source)

at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(Unknown Source)

at java.base/sun.security.ssl.SSLHandshake.consume(Unknown Source)

at java.base/sun.security.ssl.HandshakeContext.dispatch(Unknown Source)

at java.base/sun.security.ssl.SSLEngineImpl$DelegatedTask$DelegatedAction.run(Unknown Source)

at java.base/sun.security.ssl.SSLEngineImpl$DelegatedTask$DelegatedAction.run(Unknown Source)

at java.base/java.security.AccessController.doPrivileged(Native Method)

at java.base/sun.security.ssl.SSLEngineImpl$DelegatedTask.run(Unknown Source)

at java.base/java.util.ArrayList.forEach(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate.lambda$executeTasks$3(Unknown Source)

at java.net.http/jdk.internal.net.http.HttpClientImpl$DelegatingExecutor.execute(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate.executeTasks(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate.doHandshake(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader.processData(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SSLFlowDelegate$Reader$ReaderDownstreamPusher.run(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SynchronizedRestartableTask.run(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(Unknown Source)

at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(Unknown Source)

... 3 more

Caused by: java.security.cert.CertificateException: No subject alternative names matching IP address 172.19.108.30 found

at java.base/sun.security.util.HostnameChecker.matchIP(Unknown Source)

at java.base/sun.security.util.HostnameChecker.match(Unknown Source)

at java.base/sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)

at java.base/sun.security.ssl.X509TrustManagerImpl.checkIdentity(Unknown Source)

at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)

at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)

... 22 more

Traceback (most recent call last):
File "", line 23, in
File "", line 7, in makeGetRequest
File "", line 7, in makeGetRequest
at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.send(JythonHttpClient.java:103)

at com.inductiveautomation.ignition.common.script.builtin.http.JythonHttpClient.get(JythonHttpClient.java:306)

at jdk.internal.reflect.GeneratedMethodAccessor39.invoke(Unknown Source)

at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.base/java.lang.reflect.Method.invoke(Unknown Source)

java.io.IOException: java.io.IOException: Unable to GET https://172.19.108.30/index.htm

I think this is the key part.

You're trying to access this host by IP, but it has TLS/HTTPS enabled, and the IP isn't in the certificate.

Looks like your device is redirecting you to HTTPS instead of HTTP, but the device's encryption certificate only accepts access by name (not uncommon). Options:

  • Configure the device to allow HTTP.

  • Use a hostname instead of an IP address--one matching the device's own idea about its name.

  • Change the certificate in the device to include the IP address.

Thank you for all the help. I knew the device was redirecting to HTTPS and never knew what to do about it, but I will see who can help me change and configure the hostname and certificate, since I don't have those permissions.

I suppose there's one more option, but I don't recall how to do it:

  • Configure httpClient to ignore certificate problems.

You can pass bypass_cert_validation=True when constructing the httpClient.
https://docs.inductiveautomation.com/display/DOC81/system.net.httpClient