Cannot access form data in GET request - kotlin

I've been trying to make a GET request to an endpoint defined in a ktor route, but the parameters seem to be missing no matter how I try to get them. According to the documentation, I should just be able to call call.receive<Parameters>() and that should yield a map containing the data, but it's always empty.
So Far, I've tried installing my own ContentNegotiator (the convertForReceive method is never called), accessing the queryParams (always empty as well), and using the call.receiveParameters() method, which is always always empty
My CURL request looks like
curl -X GET \
http://localhost:7802/api/v2/plans \
-H 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode "id[starts_with]=asdf"
and my endpoint looks like
fun Routing.plans() {
route("plans") {
get("") {
val params = call.receive<Parameters>()
println(params)
call.respond(HttpStatusCode.NoContent)
}
}
}
I expect the parameters to contain something, but they are always empty.

I think that you won't be able to use have a body with a GET request. With that HTTP verb, most servers do not recognize a body. If you want to send a body, I'd recommend trying to change your GET request to a POST.
I think that should get you where you need to go.

Related

Using Postman Code in Unreal Engine VARest?

I'm trying to learn how to use VARest in Unreal Engine. But every tutorial uses a single URL and not a JSON input by using "Construct Json Object". My API has multiple functions, and I'm trying to use the one called "readPlayerWallet". When I view the cURL code generated by Postman, I get this:
curl --location --request
POST '---' \
--header 'Authorization: ---
--header 'Content-Type: application/json' \
--data-raw '{"query":"query readPlayerWallet ($playerGameId: String!, $network: String)
{\n readPlayerWallet (playerGameId: $playerGameId, network: $network) {\n
wallets {\n id\n type\n publicKey\n
privateKey\n createdAt\n balance\n }\n info {\n
status\n message\n }\n }\n}","variables":
{"playerGameId":"idtest","network":"---"}}'
And Postman returns a JSON file that ends with
"message":"success"}}}}
So my Unreal blueprint looks like this (Set Text's exec is connected to RestCallback, it just broke while I was taking the screenshot):
But the text disappears, and doesn't trigger isNull, so I guess it's just empty.
Why? How do I solve this?
Firstly, pull the response node and convert that to string using "to string". This will help you to check if you are getting the complete json file first.
I can't say for sure without looking at the full json file. Have you checked if the message field is directly the child of the response object or if its within an array field or another object field. If by hierarchy it has a parent array or object, you have to call it first...then from that object you have to use "get string field."
Next, check if the json is of the supported format. For example: Nested arrays are not supported by Varest.

Recieving an "errorCode: ERROR_RESOURCE_GONE" when trying to send play command

I have been trying to figure out the sonos api over the past few days, but unfortuanetly have hit a road block. I have already gotten my tokens and room names and and favorites Id, but when I send the curl request to play a song I get the error described above.
Curl Code :
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer {TOKEN}" "https://api.ws.sonos.com/control/api/v1/groups/RINCON_48A6B88A5B14014XX:XXXXXXXXXX/favorites" --data #play.json
I keep the body in a .json file called play which contains the code:
{
"favoriteId":2,
"playOnCompletion":true
}
I have not been able to find any documentation on this issue online, so any and all help is very appreciated.
The "ERROR_RESOURCE_GONE" HTTP 410 response indicates that the
groupID you are using in your request (RINCON_48A6B88A5B14014XX:XXXXXXXXXX) no longer exists. Group IDs are not static and may change depending on a number of factors - grouping and ungrouping, power cycling, etc.
If you re-run the request to get groups, you should get an up-to-date list of group IDs. Try doing that and using a returned Group ID in your favorites request.
The "Subscribe" section of the documentation describes how to automatically listen for group ID changes: https://developer.sonos.com/build/direct-control/connect/
Have you made sure that the groupId or the favoriteId are still valid? Based on the ERROR_RESOURCE_GONE, it seems one of those has likely changed.

Branch.io API keys created does not deep link, but links created in dashboard does

the links i created on the dashboard works for deep linking, but the ones i created in the API does not (it works for directing to app, but does not deep link once clicked)
LINKS:
API: https://og75.app.link/6lOctoHLLx\
CONSOLE: https://og75.app.link/lb7RahUIFx
CODE:
HTTP.post("https://api.branch.io/v1/url", :params => {
:branch_key => "KEY",
# also tried not wrapping it in data
:data => {
:linkType => "questions",
:question_id => 1
}
}).to_s
CONSOLE:
Alex from Branch.io: I'm afraid the syntax you're using to build this API call isn't familiar to me so I can't replicate locally yet.
However, a few things that might help:
You can inspect the contents of a link by appending ?debug=true to the URL (e.g., https://og75.app.link/6lOctoHLLx?debug=true). If you do this with both of your links, you'll see the API version is missing the parameters you are trying to set, which is why you don't get correct deep link behavior. Now to figure out why...
Not knowing the syntax of the call you're using in this example, I'm wondering if the data object is malformed. However, this would usually result in a 400 error with no URL returned, so I'm a little bit puzzled. If you look at our documentation for basic API link creation, you'll see the following cURL example:
Note how the contents of the data object are actually pre-escaped
curl -X POST \
\
-H "Content-Type: application/json" \
\
-d '{"branch_key":"key_live_feebgAAhbH9Tv85H5wLQhpdaefiZv5Dv", "campaign":"new_product_annoucement", "channel":"email", "tags":["monday", "test123"], "data":"{\"name\": \"Alex\", \"email\": \"alex#branch.io\", \"user_id\": \"12346\", \"$deeplink_path\": \"article/jan/123\", \"$desktop_url\": \"https://branch.io\"}"}' \
\
https://api.branch.io/v1/url
Perhaps you could try a call with the data object set as a string, and see if your link comes back with all parameters set? I have no idea if this is valid code for what you're working with, but perhaps something like this:
HTTP.post("https://api.branch.io/v1/url", :params => {
:branch_key => "KEY",
# also tried not wrapping it in data
:data => {\"linkType\": \"questions\", \"question_id\": "1"
}
}).to_s
After a lot of testing, and thanks to tips from the amazing Branch support and the debugging tips from Alex above, I finally isolated the situation.
Basically, even tho i was not using this particular parameter in iOS, I needed to add this as part of the parameters.
"$one_time_use": "",
Not doing so basically did not trigger my continueUserActivity - which is weird, even when it is the first time i am using it.

Is there a way to use a DataAccessor from Jena to use the graph store protocol with Virtuoso?

I tried to insert a dataset using a DataAccessor from jena withL
DatasetAccessor authAcc = DatasetAccessorFactory.createHTTP("http://192.168.56.101:8890/sparql-graph-crud-auth", auth);
authAcc.putModel("oole:g1",dataset.getDefaultModel());
But it does not seem to work, I also tried to PUT the same file using curl and I spotted a difference in the HTTP header.
From jena:
PUT /sparql-graph-crud-auth?graph=oole:g1 HTTP/1.1
While from curl doing:
curl --digest --user usr:pwd --verbose --url "http://192.168.56.101:8890/sparql-graph-crud-auth?graph-uri=oole:g1" -T file.ttl
I get:
PUT /sparql-graph-crud-auth?graph-uri=oole:g1 HTTP/1.1
The difference seems to be graph-uri as oppsed to graph. Is there any way i can still use the DataAccessor from Jena?
DatasetAccessor is the API to the SPARQL Graph Store Protocol and there it says graph=. This is wired into DatasetAccessorGraphHTTP.
Being open source, if you need something different you could take a copy of that one class, modify it locally (method DatasetAccessorGraphHTTP.target) to have your own implementation.
It is all built on top of some HTTP convenience code in HttpOp which you could call directly but your own modified DatasetAccessorGraphHTTP looks to be less work.

Getting response as 'Unauthorized' while sending access token via URI Query Parameter

We are creating REST API and implemented oAuth 2, using YII framework.
We are facing a strange issue, while we are trying to access the resource and sending access token via "Authorization Request Header Field" we are getting the expected output.
e.g.
curl -i -H "Accept:application/json" -H "Authorization: Bearer XXXXXX"
Whereas while we are trying to send the access token via "URI Query Parameter" we are getting response as "Unauthorized".
e.g.
https://server.example.com/resource?access_token=XXXXXX&p=q
Your suggestions would be really helpful for us.
RFC 6750 (Bearer Token Usage) defines 3 ways to pass an access token to a protected resource endpoint.
Via Authorization header. (2.1. Authorization Request Header Field)
Via a form parameter access_token. (2.2. Form-Encoded Body Parameter)
Via a query parameter access_token. (2.3. URI Query Parameter)
Among the above, only the first way is mandatory. It seems your authorization server does not support the third way.
Addition for the comment
Below is an example to support all the 3 ways in PHP. See "3. Extract Access Token" in "Protected Resource" for details and for other examples in Ruby and Java.
/**
* Function to extract an access token from a request.
*/
function extract_access_token()
{
// The value of Authorization header.
$header = $_SERVER['HTTP_AUTHORIZATION'];
// If the value is in the format of 'Bearer access-token'.
if ($header != null && preg_match('/^Bearer[ ]+(.+)/i', $header, $captured))
{
// Return the value extracted from Authorization header.
return $captured;
}
if ($_SERVER['REQUEST_METHOD'] == 'GET')
{
// Return the value of 'access_token' query parameter.
return $_GET['access_token'];
}
else
{
// Return the value of 'access_token' form parameter.
return $_POST['access_token'];
}
}
I don't know Yii, but my guess is that simply the framework does not contain code like the above.