cancel
Showing results for 
Search instead for 
Did you mean: 

passing user credentials while calling an external webservice

Baron
Participant
0 Kudos
1,110

I am consuming an external webservice from within my SQL Anywhere 17 using the following code:

create or replace function F1("JsonLoad" long varchar)

returns long varchar

url 'https://USER:PWD@localhost/index.php/mytest'

CERTIFICATE 'file=C:\\TEMP\\mycer.cer'

type 'http:post:application/json'


create or replace procedure P1("JsonLoad" long varchar)

begin

call F1(JsonLoad);

end;

The question is, how can I feed the USER & PWD from within P1?

OR

How can I change the definition of F1 so that it reads the values of USER & PWD from a table in DB

Accepted Solutions (1)

Accepted Solutions (1)

MarkCulp
Participant

You can use parameter substitution

Example (note the !user and !pwd in the url clause):

create or replace function F1( 
                    "user" long varchar,
                    "pwd"  long varchar,
                    "JsonLoad" long varchar )
returns long varchar
url 'https://!user:!pwd@localhost/index.php/mytest'
CERTIFICATE 'file=C:\\TEMP\\mycer.cer'
type 'http:post:application/json'

create or replace procedure P1("JsonLoad" long varchar)
begin
    call F1( 'myuser', 'mypassword', JsonLoad );
end;

Answers (1)

Answers (1)

VolkerBarth
Contributor

Just to add: Like Mark has shown above and answered here, web client functions (and also web client procedures) can be parameterized with the "!param" syntax - but the work to calculate or query values for these parameters must be done outside the web client functions.

Web client functions simply build a request from their input values, send it to the according web server, wait for the response and fetch and return it in the desired way. And that's all (although technically, that's certainly pretty much work...).

So in most cases you will need wrappers (usually "normal" functions/procedures like P1 in your sample) to calculate parameter values for the web client functions (say, by querying database contents and the like), then calling the web client function with these parameters, and then probably work on the web client function's return value to pick up the relevant information like error states, particular fields and the like. I have never used a web client function without having to wrap its call with one or more "outer" functions and produres.

Baron
Participant

@volker bath, thanks for the explanation and sorry for the duplicated question.

Regards