cancel
Showing results for 
Search instead for 
Did you mean: 

passing JSON Payload to procedure SQL17

Baron
Participant
1,412

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"}')

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)