Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

316
Visualizações
GET api data using curl command

I am trying to get some data from public api's using curl:

curl --request GET 'https://api.openweathermap.org/data/2.5/weather?lat=37.3565982&lon=-121.9689848&units=imperial' \
--header 'X-Api-Key: x-api-‘key \
--data 'output_format=csv' \
> save_file.csv

and if I am running the command in terminal is returning the output and everything is working just fine but if I am trying to add an extra parameter to download the result in a .csv format, is generating the file but the format inside is wrong, I mean is not added as a table format but more like a array of objects [{}, {}, {}] and so on.

It is possible to run a curl command and get the data in a csv format ?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

--data is how you add body data to a POST request. You are making a GET request.

The api documentation for the webservice you are using says:

mode optional Response format. Possible values are xml and html. If you don't use the mode parameter format is JSON by default. Learn more

So to get something other than JSON back from the server, you need to put mode=something in the query string and only XML and HTML are options.

It is not output_format.

It does not go in the body.

CSV is not an option.


If you want to put that data into CSV format, then you'll need to transform it locally. The data format described in the documentation does not look like it lends itself to the 2D data structures described by CSV so you'll have to make decisions about how to transform it.

You've tagged this javascript so you could pipe the output of curl into a program you run with Node.js which parses the JSON, restructures it however you like, and then uses a module like papaparse to convert it to JSON.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda