Please be aware that the SAP SQL Anywhere Forum will be shut down on August 29th, 2024 when all it's content will be migrated to the SAP Community.

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

asked 02 Apr '20, 13:18

Baron's gravatar image

Baron
2.2k144153181
accept rate: 48%

edited 03 Apr '20, 04:06

Volker%20Barth's gravatar image

Volker Barth
40.5k365556827

Comment Text Removed

<?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

(03 Apr '20, 03:25) Baron
Replies hidden

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)

(03 Apr '20, 03:31) Baron

@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.)

permanent link

answered 03 Apr '20, 03:37

Volker%20Barth's gravatar image

Volker Barth
40.5k365556827
accept rate: 34%

edited 03 Apr '20, 04:10

1

Oh, sorry! After changing TYPE clause into:

type 'http:post:application/json'

Then the second problem is also solved!

Thank you

(03 Apr '20, 03:56) Baron
Replies hidden

So the full question is solved?

(03 Apr '20, 04:04) Volker Barth

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

(03 Apr '20, 04:05) Baron
1

Well, I can :)

(03 Apr '20, 04:09) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×48
×33
×31

question asked: 02 Apr '20, 13:18

question was seen: 1,197 times

last updated: 03 Apr '20, 04:10