Query parameters vs json body?
Options
![Jay](https://us.v-cdn.net/6037124/user_avatars/2364889.jpg)
Jay
Member ✭
I'm not quite clear on how I set query parameters in the url, vs creating a JSON body in a POST request.
Which would this create, and how do I create the other one for this example?
[image.png]
Which would this create, and how do I create the other one for this example?
[image.png]
Comments
-
The params section of the external API request is flexible to handle both Query Parameters and JSON request body.
Path parameters would need to go on the URL line. A Path parameter example would be:
https://api.example.com/parameterA/parameterB/parameterC -
What does the image above produce?
-
I am asking explicitly how to set up this function page to create both scenarios
-
it should adapt to the API call. If it recognizes the parameters are query parameters it will append them accordingly to the URL. If they are part of a request body they would be treated as so.
Give it a try and you should see in the request object results -
Adapt how? based on if it is POST or GET?
I am getting a bad request and can't figure out why:
[image.png]
Looking at the params above it makes me thing it put them in the url instead of the body, or constructed the body wrong.
I am trying to create a Post request with this body:
{
"grant_type": "refresh_token",
"refresh_token": "502416488029-kz3mDNjrWYInCnwuzZ-UkFOt6HhOdg"
}or at least i think that is what I am supposed to send.
Maybe the problem is with the `%5B0%5D` between refresh_token and the "=" ? Not sure what that is -
Solved. My var user_refresh_token was somehow an array with one string instead of just a string.
-
sounds like you may have been using a query all records and returning a list type. This can be changed to single (or aggregate, count, existence)
-
isn’t query all records overkill when I know exactly which single record I need? -
yup! Get Record is a shortcut if you know exactly what you are looking for
-
Oh i see, i was using query all, got 1 result back but used that result to get item from user record, which resulted in an array...? Hmm.
Here is why i used query all records, because Get single record doesn't offer EVALS. Is there a way to do that with get record?
I basically need a "calculated value":
[image.png] -
- No Get Record is just a shortcut to lookup and individual record based on a single field. Once you introduce multiple parameters, joins, and advanced topics such as an eval you will want to use the Query All Records function because it is flexible and handles all that logic.
As I mentioned, Query All Records is capable of different return types: List, Single, Aggregates, etc. By default it is set to returns a list (query ALL records). Just because you might be returning 1 record does not mean you will be returning a single object return type. A list of 1 is still a list. If you want to return a single object type then you must change the return type from List to Single always. -
[CleanShot 2021-12-21 at 12.36.34.png]
-
ok cool. I just worry about querying the entire table when I know I only need one result, efficiency wise -
I know this has been answered but I'm still a bit confused on the functionality described. Michael states " The params section of the external API request is flexible to handle both Query Parameters and JSON request body. "
How do we select which mode it's in? What do we press to make it append to the URL or the body?
(I'm 70% sure I'm staring at it and not seeing it .. ) -
you don't need to do anything to differentiate when using the params section - it should append to the URL accordingly
-
I still don't understand how to send a record to an external API in the body.
There is no clear explanation anywhere.Thanks in advance
-
You have to construct the json i think, there are some examples here: https://docs.xano.com/working-with-data/functions/external-api-request#building-an-external-api-request-two-ways
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback