I'm doing a curl like the following
curl -X GET "https://api.mercadolibre.com/items/MLA511127356"
and the response is a JSON, like for example this one:
"id": "MLA511127356",
"site_id": "MLA",
"title": "Item De Testeo, Por Favor No Ofertar --kc:off",
"subtitle": null,
"seller_id": "160252486",
"category_id": "MLA4967",
"official_store_id": null,
"price": 10,
"base_price": 10,
"original_price": null,
"currency_id": "ARS",
"initial_quantity": 16,
Is there a simple way to do this?
Thank you!
How do I get JSON with Curl? To get JSON with Curl, you need to make an HTTP GET request and provide the Accept: application/json request header. The application/json request header is passed to the server with the curl -H command-line option and tells the server that the client is expecting JSON in response.
The GET method requests a specific resource from the server. GET is the default method when making HTTP requests with curl. Here is an example of making a GET request to the JSONPlaceholder API to a JSON representation of all posts: To filter the results use query params:
Because for posting a cURL request you definitely need an URL where the API is installed, but not to reply to that request because the call can come from various sources or webpages. I have successfully used cURL to request data from different APIs but of course, those APIs were already existing.
To receive JSON from a REST API endpoint, you must send an HTTP GET request to the REST API server and provide an Accept: application/json request header. The Accept header tells the REST API server that the API client expects JSON. In this REST API GET example, we make a GET request to the ReqBin echo REST API endpoint.
By using jq you could parse the json data instead of the text based parsing.
curl -X GET "https://api.mercadolibre.com/items/MLA511127356" | jq '.[].id'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With