Hi All,

I have Googled and Googled, (as well as search the forum), and I can't find a definitve answer so hoping someone can help. If this stops the question in its tracks this is SQL Anywhere 16.0.0.2076!

We have a customer using Web Services in SQL Anywhere which works fine with GET but they would like to POST the data using a JSON payload. The response type of the Web Service is set to JSON and the documentation I have found indicated that POST is setup by default with RAW, XML, JSON, etc. as available datatypes.

I can't find an example of any JSON that can/should be posted which may tell me it isn't possible but hoping someone can confirm if we can post JSON to the web service or if there is something that needs turning on.

The web service is:

CREATE SERVICE "WAddCustomer" URL PATH OFF TYPE 'JSON' USER "webuser" AS call "spaceman"."WAddCustomer"("idoreturn" = "HTTP_VARIABLE"('idoreturn'),"isite" = "HTTP_VARIABLE"('isite'), "isurname" = "HTTP_VARIABLE"('isurname'));

Calling the target:

https://localhost:8082/WebTest/WAddCustomer

POSTing:

{ "idoreturn":"1" "isite":"RI0XTEJM071220170001" "isurname":"Squires" }

I have tried putting this all into an ARRAY as well as the return is all in an ARRAY, (see below), and wondered if that was the format SQL Anywhere required.

I always get the return that

[ { "customerid":"INVALID" }]

The return is coming from the function and in debug I can certainly see no data is being received by it hence the "INVALID return.

Is this possible or does the data have to be posted data pairs or similar?

Thanks,

Alasdair

asked 05 Jan, 07:09

RADicalSYS's gravatar image

RADicalSYS
28681329
accept rate: 11%


{ "idoreturn":"1" "isite":"RI0XTEJM071220170001" "isurname":"Squires" }

FWIW, that's no valid JSON string, members of an object have to be separated via commas, see here for reference.


That being said, the docs on CREATE SERVICE do tell:

The database server does not parse the JSON input automatically. It is up to the application to parse it.

So I would assume that it won't work to use

idoreturn" = "HTTP_VARIABLE"('idoreturn')...
when calling the procedure. I would assume you need to call the procedure with the whole body as variable and within the procedure (probaby via the builtin sp_parse_json() procedure) separate the elements of the JSON object.

permanent link

answered 05 Jan, 07:28

Volker%20Barth's gravatar image

Volker Barth
39.2k354537806
accept rate: 33%

converted 05 Jan, 07:38

Sorry about the JSON - I couldn't copy and paste from the other PC so typed all this in and, as pointed out I missed the commas. Doh.

I did see it mentioned about not parsing the JSON but I think from Volker's answer I understand rather more what that means now, (or rather that it means it's a PITA to do).

Will see what the client says about posting the data just as key-value pairs - it's not very different to the JSON anyway in the basic way it needs sent!

Thanks for the input.

(05 Jan, 08:32) RADicalSYS
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:

×62
×27
×2

question asked: 05 Jan, 07:09

question was seen: 183 times

last updated: 05 Jan, 08:32