on 2020 Apr 02 2:18 PM
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"}')
@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.)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, sorry! After changing TYPE clause into:
type 'http:post:application/json'
Then the second problem is also solved!
Thank you
Well, I can 🙂
User | Count |
---|---|
70 | |
11 | |
10 | |
10 | |
9 | |
9 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.