Using request["data"] in doGet() python resource in Web Dev

I’m trying to receive a list or dictionary using request[“data”] in doGet() python resource but not sure how to send data to the resource

GET requests do not (cannot) have a body; you need to use URL parameters (and thus, request["params"]) to pass data to a GET endpoint.

Query parameters go into the URL directly; start query params with a ?, separate them with & and, if necessary, URL-encode any non-basic-ASCII values:
system/webdev/test/asdf?param=1&param2=2&param=2

1 Like

can POST request have a body?
how can we use request[“data”]?

Yes, POST requests accept an incoming body. There are examples here on the forum.

1 Like

使用script library 的第三方脚本可以事项 DoGet 传递Body 值

Is this a question?

Via Google Translate

The doGet() method in WebDev can certainly pass the body content to a script in that project's script library. I'm not sure if that is precisely what you meant.

2 Likes

Are you sure about this? I may be misunderstanding you, but I just set up a doGet webdev endpoint and pass in request.data directly that I use as parameters to a named query and it works - did you mean something else?

Edit: Snip of my setup

My query data result is in json format using 'FOR JSON PATH' clause. When returning this value from Web Dev - doGet method, it is not showing in the same format. It is splitting the data into multiple blocks. How do I send the query result in doGet return statement?

Can you explain or show what you mean by multiple blocks?

Thanks for the response, the blocks are like this:
[
[
25 rows added here
],
[
25 rows added here
],
[
25 rows added here
]
]

Can you show the output of the named query outside of the doGet call? There's nothing in the endpoint (afaik) or the decode function that would break up the response like that.

Are you running the query with the same parameters when you're testing outside of WebDev?

The query is just a simple select statement and the result is like this with more than 100 locations,
{"Data":[{"Location":"01","ALocation":4,"Type":"M"},{"Location":"02","ALocation":105,"Type":"M"}]}

SELECT Location, ALocation, Type
FROM table1
FOR JSON PATH, ROOT ('Data');

def doGet(request, session):
value = system.dataset.toPyDataSet(system.db.runNamedQuery("query1"))
jsonString = system.util.jsonEncode(value)
return {'json':value}
# return {'json':jsonString} -- returns the same result when launched

If I remember SQL Server json encoding correctly, you should just be able to do this:

def doGet(request, session):
    locations = system.db.runNamedQuery("query1")
    return {"json": locations}

since locations is already a JSON string. You would need to jsonDecode if you wanted to return a dict instead of JSON. Try that out and see how it goes.

Also, I feel like you might find encode/decode errors in the logs if the parameters are in the correct format, I would check those.

Found the issue is related to the browser where I was checking the results. Chrome shows correctly, and Edge splitting the data. Thank you for responding to my request!

1 Like