v2.ocaml.org icon indicating copy to clipboard operation
v2.ocaml.org copied to clipboard

Create script to fetch company data from stackshare api

Open Bhavika-Gianey opened this issue 3 years ago • 3 comments

Issue Description

In addition to the locally maintained lists, stackshare has a list of companies using OCaml https://stackshare.io/ocaml The issue is to generate a JSON file from the stackshare API.

Please include a summary of the issue.

Work in progress #1503

Changes Made

I tried to fetch data from the API but it is showing this error:

pp

Please describe the changes that you made.

  • Please check if the PR fulfills these requirements
  • [x] PR is descriptively titled and links the original issue above
  • [ ] Before/after screenshots (if this is a layout change)
  • [x] Details of which platforms the change was tested on (if this is a browser-specific change)
  • [x] Context for what motivated the change (if this is a change to some content)

Bhavika-Gianey avatar Apr 28 '21 21:04 Bhavika-Gianey

Hii @patricoferris, can you please help me resolve this.

Bhavika-Gianey avatar Apr 28 '21 21:04 Bhavika-Gianey

As @gs0510 quite rightly mentioned Ezjsonm.to_string in converting our value to a JSON string, this can be transferred over the internet to the API.

I suggest having a play around with it in utop for example:

utop # Ezjsonm.to_string (`O ["hello", `String "world"]);;
- : string = "{\"hello\":\"world\"}"

Most GraphQL APIs (afaik) understand the body as a JSON object where they query is stored as a value associated with a key called query (there are other things you can add to like variables etc.) so that's what we're doing in that part of the code:

{
  "query": "query { ... }"
}

Also as a general rule it is pretty bad to commit API keys into any code. Other people could abuse it but the blame may come back to you since it is your API key. I don't think anyone here would do that of course, but just letting you know :)) You probably want to disable that API key and generate a new one.

patricoferris avatar Apr 30 '21 09:04 patricoferris

Thanks, @gs0510, @patricoferris, I understood the use of Ezjsonm.to_string and I will generate a new API Key. But I am still getting the error of no query string present.

pp. :((.

I think the error is caused due to the presence of arguments inside the query but I don't know how to resolve that. Plse kindly look into this and help me.

Bhavika-Gianey avatar May 02 '21 20:05 Bhavika-Gianey