Using Postman Code in Unreal Engine VARest? - api

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.

Related

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.

Cannot access form data in GET request

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.

How to fix 'SyntaxError: Unexpected token # in JSON at position 0' - POST null body

I have a cloud function running Express to serve as a web hook endpoint.
My client sends a POST request with a null body value.
And the service returns 400 Bad Request with this log :
SyntaxError: Unexpected token # in JSON at position 0
at Object.parse (native)
at createStrictSyntaxError (/var/tmp/worker/node_modules/body-parser/lib/types/json.js:157:10)
at parse (/var/tmp/worker/node_modules/body-parser/lib/types/json.js:83:15)
at /var/tmp/worker/node_modules/body-parser/lib/read.js:121:18
at invokeCallback (/var/tmp/worker/node_modules/raw-body/index.js:224:16)
at done (/var/tmp/worker/node_modules/raw-body/index.js:213:7)
at IncomingMessage.onEnd (/var/tmp/worker/node_modules/raw-body/index.js:273:7)
at emitNone (events.js:86:13)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:978:12)
But null is a valid JSON value. Any other correct JSON value seems fine.
As more concrete exemples :
response 200 :
curl -d '{"foo": true}' -H "Content-Type: application/json" -X POST {endpoint_url}
response 400 / SyntaxError :
curl -d null -H "Content-Type: application/json" -X POST {endpoint_url}
Express doesn't seem to be reached, so I suppose the request is parsed and validated upfront?
How can I log the request to analyze why it is rejected?
thank you
If we look at the stack trace from the code, we find that it points to approximately here (source). Reading that code, we then seem to find that the expected/required input data must be JSON that starts with either { (an object) or [ (an array). This would mean that null or even a scalar value would fail with the error described.
If we then look at the documentation of bodyParser found here we read about an option called strict which, when set to true instructs our parser to only accept objects or arrays while when false allows us to accept scalars too. Since the default on strict is true, my assumption is that one can only pass in objects or arrays.
If this is the case, then sending in null would be an invalid / unsupported parameter. It could be that if you need to send in a single scalar value, send it in as a value of a field in an object:
{
"value": null
}
or as an element in an array
[null]

Vimeo API - Get categories and credits

I'm doing a script that takes a video ID from Vimeo, calls the API and populate the database with all the data we need.
I'm able to get all the fields and everything is working well using that url:
https://api.vimeo.com/videos/{video_id}
I can also use the query ?fields=name, etc... To only get the fields i need.
But when i make that request to the API (even when i use the fields query), the categories array is empty and the credits are returned as this:
"credits": {
"uri": "/videos/{video_id}/credits",
"options": [
"GET",
"POST"
],
"total": 1
}
If i make another request, to those url:
https://api.vimeo.com/videos/{video_id}/credits
https://api.vimeo.com/videos/{video_id}/categories
I get all the info i need about the credits and categories.
The problem is: i do not want to make 3 request to the API to get everything i need. Why are the credits and categories not included in the original video request?
Is there a way i can do it with one call?
Regarding categories, the video may not be categorized, either by the video owner or a Vimeo Curator. When a video has not been categorized, the categories array will return empty.
For example, this test video returns no categories:
curl -X GET
'https://api.vimeo.com/videos/76979871?fields=uri,categories'
-H 'Accept: application/vnd.vimeo.*+json;version=3.4'
-H 'Authorization: bearer [token]'
While this Staff Picked video returns several categories and subcategories:
curl -X GET
'https://api.vimeo.com/videos/274849065?fields=uri,categories.uri,categories.uri,categories.name,categories.top_level'
-H 'Accept: application/vnd.vimeo.*+json;version=3.4'
-H 'Authorization: bearer [token]'
Regarding credits, a video will always have a minimum of one credit (the video owner). I suggest adding some logic so that if metadata.connections.credits.total is greater than 1, then make the additional request to get those other credited users.
For instance, this same Staff Picked video returns metadata.connections.credits.total=2, so to get the additional credited user, you'll need to make a request to the video's credits endpoint.
curl -X GET
'https://api.vimeo.com/videos/274849065?fields=uri,metadata.connections.credits'
-H 'Accept: application/vnd.vimeo.*+json;version=3.4'
-H 'Authorization: bearer [token]'
The reason for the separate endpoint for credits is that each user object can contain a lot of metadata -- if a video credits many users, the video response (which is already quite large) can be even bigger if the fields parameter isn't used.
I hope this information helps!

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.