http:send-request / http:request with Azure API key

Saturday, 5 September 2020 · 5 messages · last reply 6 Sep 2020
JA
Jozef Aerts5 Sep 2020 08:49 #
Dear colleagues, We are using XQuery with BaseX for the development of hundreds of validation rules for CDISC Standards ("Open Rules for CDISC Standards"). For some of these rules we need a lookup using a RESTful web server located at CDISC. Until now, that server used basic authentication until now, but they are moving to using an Azure API key. For the new mechanism, the curl request is:
     curl -X GET https://ngp-apim-dev.azure-api.net/api/mdr/products \
-H "Accept: application/json" \ -H "Ocp-Apim-Subscription-Key: abcdef0123456789abcdef0123456789" So, based on the documentation at https://docs.basex.org/wiki/HTTP_Client_Module, for XQuery I used:
let $response := http:send-request(

<http:request method='get' href='https://ngp-apim-dev.azure-api.net/api/mdr/products'>

<http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/>

</http:request>)
and:
     let $response := http:send-request(

<http:request method='get'>

<http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/>

</http:request>,'https://ngp-apim-dev.azure-api.net/api/mdr/products')
where $apikey is my personal key, which works when working with curl or in a Java program. but I get a "Connection failed". From a few experiments, it looks as the server is reached, but then refuses to do something with the request. I cannot see however what the details of the failure is. Any idea what I am doing wrong? Many thanks in advance, Jozef Aerts XML4Pharma
CG
Christian Grün5 Sep 2020 19:22 #
Hi Jozef, I tried the following query…
http:send-request(
<http:request method='get'
href='https://ngp-apim-dev.azure-api.net/api/mdr/products'>
<http:header name="Ocp-Apim-Subscription-Key"
value="abcdef0123456789abcdef0123456789"/>
</http:request>)
…and it returned the error message 'Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription.'. I guess that’s expected because the key is not valid anymore. Do you get the same response as above with wrong keys, though, or do you get "Connection failed"? Is the connection failure accommodated by an error code, an HTTP response header or anything else? Feel free to provide us with more information if there’s any chance to reproduce the problem. Next, feel free to share the verbose curl output for the successful request with us (-v). Best Christian
Quoted text · Jozef Aerts · 34 lines
On Sat, Sep 5, 2020 at 8:49 AM Jozef Aerts <basex at xml4pharma.com> wrote: > > Dear colleagues, > We are using XQuery with BaseX for the development of hundreds of validation rules for CDISC Standards ("Open Rules for CDISC Standards"). > For some of these rules we need a lookup using a RESTful web server located at CDISC. Until now, that server used basic authentication until now, but they are moving to using an Azure API key. > For the new mechanism, the curl request is: > > curl -X GET https://ngp-apim-dev.azure-api.net/api/mdr/products \ > -H "Accept: application/json" \ > -H "Ocp-Apim-Subscription-Key: abcdef0123456789abcdef0123456789" > > So, based on the documentation at https://docs.basex.org/wiki/HTTP_Client_Module, for XQuery I used: > let $response := http:send-request( > <http:request method='get' href='https://ngp-apim-dev.azure-api.net/api/mdr/products'> > <http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/> > </http:request>) > > and: > let $response := http:send-request( > <http:request method='get'> > <http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/> > </http:request>,'https://ngp-apim-dev.azure-api.net/api/mdr/products') > > where $apikey is my personal key, which works when working with curl or in a Java program. > > but I get a "Connection failed". > > From a few experiments, it looks as the server is reached, but then refuses to do something with the request. I cannot see however what the details of the failure is. > > Any idea what I am doing wrong? > > Many thanks in advance, > Jozef Aerts > XML4Pharma
JA
Jozef Aerts5 Sep 2020 19:35 #
The key I gave you was of course just a sample, as I am not allowed to make the real one available to others ... I got the "Connection failed" with my valid key (well, it works in my Java implementation), when using the BaseX GUI as implemented in Apache Tomcat. Maybe that is the reason. I will try running the query from within another program without GUI (e.g. a Java program using the BaseX library), and see what happens then. I will do so later tonight or tomorrow morning, and then let you know. Many thanks already, Jozef
Quoted text · Christian Grün · 270 lines
> > > Christian Grün <christian.gruen at gmail.com> hat am 05.09.2020 19:22 geschrieben: > > > > > > > > > > > > Hi Jozef, > > > > > > > > I tried the following query… > > > > > > > > http:send-request( > > > > <http:request method='get' > > > > href='https://ngp-apim-dev.azure-api.net/api/mdr/products'> > > > > <http:header name="Ocp-Apim-Subscription-Key" > > > > value="abcdef0123456789abcdef0123456789"/> > > > > </http:request>) > > > > > > > > …and it returned the error message 'Access denied due to invalid > > > > subscription key. Make sure to provide a valid key for an active > > > > subscription.'. > > > > > > > > I guess that’s expected because the key is not valid anymore. Do you > > > > get the same response as above with wrong keys, though, or do you get > > > > "Connection failed"? Is the connection failure accommodated by an > > > > error code, an HTTP response header or anything else? > > > > > > > > Feel free to provide us with more information if there’s any chance to > > > > reproduce the problem. Next, feel free to share the verbose curl > > > > output for the successful request with us (-v). > > > > > > > > Best > > > > Christian > > > > > > > > > > > > > > > > On Sat, Sep 5, 2020 at 8:49 AM Jozef Aerts <basex at xml4pharma.com> wrote: > > > > > > > > > > > > > > Dear colleagues, > > > > > > > > We are using XQuery with BaseX for the development of hundreds of validation rules for CDISC Standards ("Open Rules for CDISC Standards"). > > > > > > > > For some of these rules we need a lookup using a RESTful web server located at CDISC. Until now, that server used basic authentication until now, but they are moving to using an Azure API key. > > > > > > > > For the new mechanism, the curl request is: > > > > > > > > > > > > > > curl -X GET https://ngp-apim-dev.azure-api.net/api/mdr/products \ > > > > > > > > -H "Accept: application/json" \ > > > > > > > > -H "Ocp-Apim-Subscription-Key: abcdef0123456789abcdef0123456789" > > > > > > > > > > > > > > So, based on the documentation at https://docs.basex.org/wiki/HTTP_Client_Module, for XQuery I used: > > > > > > > > let $response := http:send-request( > > > > > > > > <http:request method='get' href='https://ngp-apim-dev.azure-api.net/api/mdr/products'> > > > > > > > > <http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/> > > > > > > > > </http:request>) > > > > > > > > > > > > > > and: > > > > > > > > let $response := http:send-request( > > > > > > > > <http:request method='get'> > > > > > > > > <http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/> > > > > > > > > </http:request>,'https://ngp-apim-dev.azure-api.net/api/mdr/products') > > > > > > > > > > > > > > where $apikey is my personal key, which works when working with curl or in a Java program. > > > > > > > > > > > > > > but I get a "Connection failed". > > > > > > > > > > > > > > From a few experiments, it looks as the server is reached, but then refuses to do something with the request. I cannot see however what the details of the failure is. > > > > > > > > > > > > > > Any idea what I am doing wrong? > > > > > > > > > > > > > > Many thanks in advance, > > > > > > > > Jozef Aerts > > > > > > > > XML4Pharma > > > > > > > >
JA
Jozef Aertsin reply to Christian Grün, 5 Sep 2020, 19:226 Sep 2020 07:41 #
The "Connection failed" was when using the GUI when BaseX911.war was deployed on an Apache Tomcat, and then using: http://localhost:8080/BaseX911/dba/queries When however running from within a Java program (with a valid API key of course), it went fine. For development of new queries, that is however not a good option. I now however discovered the native BaseX GUI (wasn't aware of it) and there, the query runs just fine. So for development and testing, that will be the first choice from now on. Just as a side question: any idea why the query does not run when using the GUI within Apache Tomcat? Many thanks again for taking care! Jozef
Quoted text · Christian Grün · 270 lines
> > > Christian Grün <christian.gruen at gmail.com> hat am 05.09.2020 19:22 geschrieben: > > > > > > > > > > > > Hi Jozef, > > > > > > > > I tried the following query… > > > > > > > > http:send-request( > > > > <http:request method='get' > > > > href='https://ngp-apim-dev.azure-api.net/api/mdr/products'> > > > > <http:header name="Ocp-Apim-Subscription-Key" > > > > value="abcdef0123456789abcdef0123456789"/> > > > > </http:request>) > > > > > > > > …and it returned the error message 'Access denied due to invalid > > > > subscription key. Make sure to provide a valid key for an active > > > > subscription.'. > > > > > > > > I guess that’s expected because the key is not valid anymore. Do you > > > > get the same response as above with wrong keys, though, or do you get > > > > "Connection failed"? Is the connection failure accommodated by an > > > > error code, an HTTP response header or anything else? > > > > > > > > Feel free to provide us with more information if there’s any chance to > > > > reproduce the problem. Next, feel free to share the verbose curl > > > > output for the successful request with us (-v). > > > > > > > > Best > > > > Christian > > > > > > > > > > > > > > > > On Sat, Sep 5, 2020 at 8:49 AM Jozef Aerts <basex at xml4pharma.com> wrote: > > > > > > > > > > > > > > Dear colleagues, > > > > > > > > We are using XQuery with BaseX for the development of hundreds of validation rules for CDISC Standards ("Open Rules for CDISC Standards"). > > > > > > > > For some of these rules we need a lookup using a RESTful web server located at CDISC. Until now, that server used basic authentication until now, but they are moving to using an Azure API key. > > > > > > > > For the new mechanism, the curl request is: > > > > > > > > > > > > > > curl -X GET https://ngp-apim-dev.azure-api.net/api/mdr/products \ > > > > > > > > -H "Accept: application/json" \ > > > > > > > > -H "Ocp-Apim-Subscription-Key: abcdef0123456789abcdef0123456789" > > > > > > > > > > > > > > So, based on the documentation at https://docs.basex.org/wiki/HTTP_Client_Module, for XQuery I used: > > > > > > > > let $response := http:send-request( > > > > > > > > <http:request method='get' href='https://ngp-apim-dev.azure-api.net/api/mdr/products'> > > > > > > > > <http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/> > > > > > > > > </http:request>) > > > > > > > > > > > > > > and: > > > > > > > > let $response := http:send-request( > > > > > > > > <http:request method='get'> > > > > > > > > <http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/> > > > > > > > > </http:request>,'https://ngp-apim-dev.azure-api.net/api/mdr/products') > > > > > > > > > > > > > > where $apikey is my personal key, which works when working with curl or in a Java program. > > > > > > > > > > > > > > but I get a "Connection failed". > > > > > > > > > > > > > > From a few experiments, it looks as the server is reached, but then refuses to do something with the request. I cannot see however what the details of the failure is. > > > > > > > > > > > > > > Any idea what I am doing wrong? > > > > > > > > > > > > > > Many thanks in advance, > > > > > > > > Jozef Aerts > > > > > > > > XML4Pharma > > > > > > > >
JB
James Ball6 Sep 2020 13:03 #
Hello Jozef, I see that you’ve made some progress with your issue but in case it helps I think I had a very similar problem at one point - my computer would happily connect to an SSL server but BaseX could not. I cannot remember the details with certainty but IIRC it was caused by me running the BaseX server using a particular version of the Java Runtime which had a very old certificate store. I think I was able to change to a different version of Java (or update the certificate store to a more recent one) and the problem went away. I don’t know if I was missing a a root certificate or something had expired. Regards, James
Quoted text · basex-talk-request at mailman.uni-konstanz.de · 43 lines
> On 5 Sep 2020, at 11:00, basex-talk-request at mailman.uni-konstanz.de wrote: > > > From: Jozef Aerts <basex at xml4pharma.com> > Subject: [basex-talk] http:send-request / http:request with Azure API key > Date: 5 September 2020 at 07:49:31 BST > To: "basex-talk at mailman.uni-konstanz.de" <basex-talk at mailman.uni-konstanz.de> > > > Dear colleagues, > We are using XQuery with BaseX for the development of hundreds of validation rules for CDISC Standards ("Open Rules for CDISC Standards"). > For some of these rules we need a lookup using a RESTful web server located at CDISC. Until now, that server used basic authentication until now, but they are moving to using an Azure API key. > For the new mechanism, the curl request is: > > curl -X GET https://ngp-apim-dev.azure-api.net/api/mdr/products \ > -H "Accept: application/json" \ > -H "Ocp-Apim-Subscription-Key: abcdef0123456789abcdef0123456789" > > So, based on the documentation at https://docs.basex.org/wiki/HTTP_Client_Module, <https://docs.basex.org/wiki/HTTP_Client_Module>for XQuery I used: > let $response := http:send-request( > <http:request method='get' href='https://ngp-apim-dev.azure-api.net/api/mdr/products'> > <http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/> > </http:request>) > > and: > let $response := http:send-request( > <http:request method='get'> > <http:header name="Ocp-Apim-Subscription-Key" value="{$apikey}"/> > </http:request>,'https://ngp-apim-dev.azure-api.net/api/mdr/products') > > where $apikey is my personal key, which works when working with curl or in a Java program. > > but I get a "Connection failed". > > From a few experiments, it looks as the server is reached, but then refuses to do something with the request. I cannot see however what the details of the failure is. > > Any idea what I am doing wrong? > > Many thanks in advance, > Jozef Aerts > XML4Pharma > >

⚡Generated with XQuery