How to consume a Graphql API (https://api.loggi.com)

Asked

Viewed 1,111 times

4

I would like to understand know and know opinions to apply in a project urgently... I currently have a shopping website and I need to use the loggi company API which is a distribution company the api link is https://api.loggi.com, I’ve used their old methods to check the price of the zip code but to do more robust searches like Login, Order Tracking, etc... they tell me to use the new method that is with Graphql, I already created a project in Node.js using simple local as Hello World, but I don’t understand how to configure it to run for example the script below that is to locate the registered cities

$ curl -v 'https://staging.loggi.com/graphql?' \
>     -H 'content-type: application/json' \
>     -H 'authorization: ApiKey [email protected]:a-valid-api-key' \
>     --compressed \
>     --data-binary '{"query":"query { allCities { edges { node { pk name slug } } } }"}'
>
> POST /graphql? HTTP/1.1
> Host: staging.loggi.com
> content-type: application/json
> ApiKey [email protected]:a-valid-api-key
>
< HTTP/1.1 200 OK
< Content-Type: application/json
<
{"data":{"allCities":{"edges":[{"node":{"pk":4,"name":"Curitiba","slug":"ct"}},{"node":{"pk":1,"name":"S\u00e3o Paulo","slug":"sp"}},{"node":{"pk":2,"name":"Rio de Janeiro","slug":"rj"}},{"node":{"pk":3,"name":"Belo Horizonte","slug":"bh"}},{"node":{"pk":5,"name":"Porto Alegre","slug":"pa"}}]}}}

Has anyone ever used this API or similar API ? (I don’t know if CURL would be a js request or Graphql itself)

Note: My site is done in Asp.net Webforms and excuse the ignorance for lack of knowledge, I did research and more research on Graphql and understood only that it is an easy way to read an API. So I also researched the CURL would be equivalent to Webrequest in c#, I’m sure?

Old method I could use that would be with their Restful API and was just a JSON request, didn’t need login, apikey and no credential:

 {
        "transport_type": 1,
        "city": 1,
        "addresses": [
            {
                "by": "cep",
                "query": {
                    "cep": "01426000",
                    "number": 300
                }
            },
            {
                "by": "address",
                "query": {
                    "category": "Rua",
                    "address": "Oscar Freire",
                    "number": 100
                }
            }
        ]
    }
  • But if you can access the api via Graphql, you can also access Asp.net.

  • @That’s the thing, I can’t access the API.

  • I have downloaded the Api, and you need to create a login on the site through this link: https://www.loggi.com/contas/create/ and after this, you must access this link: https://www.loggi.com/contas/haxor/ for your Key to be generated, so just use the API normally in C#.

  • Hello To be able to consume an API Graphql Voce you need a client to be able to middleware between Graphql and its application below some: - Apollo Client: https://apollographql.com/ - Relay: https://facebook.github.io/relay/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.