hi
i have a HTTP module that sends back this data :
{
"asks": [
{
"price": "555820",
"amount": "2.168000"
}
],
"bids": [
{
"price": "555750",
"amount": "3.947000"
}
]
}
i want to fetch the “price” in a json module but i cant. i dont know how to get the price data from this json that has array in it. can anyone help me with this?
Hi @alireza_soleimanikha!
Welcome to the Make forum!
If you tick this box in the HTTP module, then Make will parse the JSON for you.
This will then expose it so that you can map it in later modules, something like this:
If you do not want your HTTP module to parse the JSON directly (perhaps because you need to manipulate the input in some way), then you use a Parse JSON module to convert the text returned from the HTTP module into a JSON object.
You can map it in later modules, something like this:
This returning the first value from your array. So is equivalent to this:
Make is capable of more complex manipulation if you need it. Let us know how you get on, and if you have any problems, pop a few screenshots on this thread and we’ll do our best to help you out.
4 Likes
Welcome to the Make community!
There might be multiple asks or bids, since the server is returning an array.
You can either use an array Iterator on the “asks” and “bids” variable, or to get the first item of each array, you can also use the map
function
{{ first(map(asks; "price")) }}
{{ first(map(bids; "price")) }}
Links
Here are some useful links and guides you can use to learn more on how to use the Make platform, apps, and app modules. I found these useful when I was learning Make, and hope they might benefit you too —
General
Help Center Basics
Articles & Videos
3 Likes
i dont know why i cant get this to work
i also exported the blueprint so you can see the project and i attach the file for you
blueprint (1).json (15.5 KB)
i have a HTTP module and i have a GET request to this URL : https://api.exbito.com/apiv2/markets/USDT_IRR/depth?interval=0&limit=1
this URL does not need any header or query
you get this response from the HTTP above :
{
“asks”: [
{
“price”: “557720”,
“amount”: “15.216000”
}
],
“bids”: [
{
“price”: “557700”,
“amount”: “22.647000”
}
]
}
After the HTTP module i have a JSON module so i Parse the Json
for the structure i generated it from the Json above and for JSON string i use Data from HTTP module
then i pass it to the Telegram module so i can send a message to my telegram channel
but when i send it to telegram i get this error :
Missing value of required parameter ‘text’.
here are pics from JSON module and my Telegram Module
in telegram module in Text i also tried
{{first(map(3.bids; 1))}}
but its not working i dont know what am i doing wrong here
if you have time please look at the Blueprint that i attached
Hi @alireza_soleimanikha,
You are very close, but you are mixing up the two different methods suggested. You are currently passing the whole bids array to the Telegram module, rather than just the text inside the array.
The simplest method is the one I suggested. You don’t need the map()
function or the first()
function, because your API is only returning 1 value. So just use bids.price to copy your price value into the Telegram module:
If you cannot see this in the mapping list, you can type it as: {{3.bids.price}}
To make a more complex message within your Telegram bot, you can embed parts of the array into your Text field, like this:
Good luck!
3 Likes
Hi Terry thx for your time
i did as you said but i get the same error here is the picture of my telegram module
Have you tried a hardcoded message without mapping anything?
1 Like
Hi @alireza_soleimanikha,
It looks like the data is not coming from the API in the way you described.
This screenshot from earlier shows a different data structure from the one you included in your question.
In that image, the array of items within your “bids” is empty. It should look like this:
Look at the data coming out of your JSON module, by clicking the circle above it after running the scenario. It should look like this:
If it doesn’t, then your problem is earlier in the process, perhaps with the data being returned by the API.
2 Likes
I took your blueprint @alireza_soleimanikha and added a set multiple variables to extract the data from your HTTP response. You don’t need a Parse JSON module if you turn on Parse JSON in the HTTP Module which I have done. Take a look here and you can use the variables in the rest of your scenario. Or you can eliminate it and just use the {{1.data.asks[].price}}
and the other 3 expressions directly in the Telegram app.
Download blueprint.json (11.7 KB)
3 Likes
hi alex
i imported your blueprint ran it and as you can see the output of it is empty for the variables
but HTTP Data has value and its not empty
i dont know why its empty
Does the HTTP module have Parse response
set to “Yes”? Please check that and send a screen shot of how it is configured. Also show the output bundle here by download it and pasting it here from HTTP module.
Heres the parsed JSON I get out of the HTTP module for the data
structure.
...
"data": {
"asks": [
{
"price": "559960",
"amount": "108.443000"
}
],
"bids": [
{
"price": "556400",
"amount": "15.769000"
}
]
},
...
2 Likes
for simplicity i just changed the URL so i can make this one to work but i cant
the URL is
https://api.exbito.com/apiv2/markets/USDT_IRR/depth?interval=0&limit=1
and the response data is in this format
{
“asks”: [
{
“price”: “556240”,
“amount”: “9.903000”
}
],
“bids”: [
{
“price”: “556210”,
“amount”: “5.847000”
}
]
}
it should be really simple with just 2 or 3 modules but i cant figure this out.
i have some complex scenarios and they are working for weeks but this one i cant get it right
Send your scenario as a blueprint so I can have a look… If you have Parse response
turned off the results are what you are seeing: empty values. So make sure it is turned on in the HTTP module
2 Likes
here is the blueprint
blueprint (2).json (17.9 KB)
I imported your blueprint, unlinked the Telegram app to run it successfully and get values:
Maybe try to make the scenario from scratch again? Seems like it may be corrupted. You can just make a new scenario and import your blueprint.
2 Likes
i unlinked it from telegram now and when i want to run the module i get this window. should i do anything with this? if i press “ok” after RUN the variables are empty like before. and why it should relate to Telegram Module that is after it?
and this is after RUN and all variables are empty
If you just try to run the Set Multiple Variables modules on its own it will ask you for the input bundles. Did you create a new scenario and import the scenario you sent me?
2 Likes
I just unlinked Telegram when I ran it because I don’t have a connection ready for it so it will fail to run altogether unless I make a Telegram connection and configure the module.
2 Likes
if you want you can send me your scenario and i test it without changing any parameter.
maybe its a bug in the site?
ok here is the solution
the most important part is your data structure in JSON module
i copied the json format from my HTTP Output then inserted it in JSON module data structure
and now everything is ok.
i did it with all of my other API calls also and now all of them working
thx for everyone’s support
3 Likes