cancel
Showing results for 
Search instead for 
Did you mean: 

passing JSON Payload to procedure SQL17

Baron
Participant
1,366

I want to call an external API using an internal function in SQL-Anywhere 17:

create or replace function TokenRequest ("JsonPayLoad" long varchar)
returns long varchar
url 'http://localhost/api/token'
Header 'Content-Type: application/json';

The JsonPayLoad looks like:

{

"grant-type": "client-credentials",

"scopes": "read"

}

When I call this API using CURL (under windows) I should add \\ as escape sequence, so the call on CURL looks like this (it works):

curl -X POST "http://localhost/api/token" --header "Content-Type: application/json" --data "{\\"grant-type\\": \\"client-credentials\\",\\"scopes\\": \\"read\\"}"

My question how should I pass the JsonPayload to my TokenRequest function?

This one for example brings an Status=400; Bad Request:

call TokenRequest('"{"grant-type": "client-credentials","scopes": "read"}')

Baron
Participant
0 Kudos

<?xml version="1.0"?>

<SOAP-ENV:Envelope

xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsd="http://www.w3.org/2001/XMLSchema"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">

<soap-env:body>

<m:tokenrequest xmlns:m="http://localhost:80">

 <JsonLoad xsi:type="xsd:string">{&qot;grant_type&qot;:

&qot;client_credentials&qot;,&qot;scopes&qot;: &qot;read&qot;}</jsonload>

</m:tokenrequest>

</soap-env:body>

</soap-env:envelope>

Above I replaced each quot with qot, in order to prevent the escape sequence

Baron
Participant
0 Kudos

My question is, why the body is sent as SOAP and XML, and why all quotation marks are replaced with & q u o t ; (without spaces)

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

@Sako asked:

My question is, why the body is sent as SOAP and XML, and why all quotation marks are replaced with & q u o t ; (without spaces)


It's using SOAP because the docs say so 🙂

TYPE clause
Specifies the format used when making the web service request. SOAP:RPC is used when SOAP is specified or no TYPE clause is included. HTTP:POST is used when HTTP is specified.

and your create function statement does not use a TYPE clause.

(I have not used JSON with web client functions/procedures so I can't help on the other issues.)

Baron
Participant

Oh, sorry! After changing TYPE clause into:

type 'http:post:application/json'

Then the second problem is also solved!

Thank you

VolkerBarth
Contributor
0 Kudos

So the full question is solved?

Baron
Participant
0 Kudos

Yes, but I can't convert your comment to answer 😞

VolkerBarth
Contributor

Well, I can 🙂

Answers (0)