Make an API request

The Mobilic API is a web service (based on the HTTP protocol) that uses the GraphQL standard.

GraphQL

Unlike REST architectures where the HTTP verb and the URI will characterize the operation, all requests to the GraphQL API will share the same HTTP POST verb and the same URI.

This unique URI depends on the environment:

The details of the operation will be specified in the JSON body of the request.

A basic example

All actions that can be performed on the API require to have created a Mobilic account, and almost all require to be authenticated.

For this basic example, we will take an operation that displays the email, the name, and the Mobilic ID of the user, using the operation me

The body of the query, in JSON format, must contain a query field that specifies the operation. The value of this field query is for the operation me:

query {
    me {
        id
        lastName
        email
    }
}

To build the JSON body of the query, simply put the text of the operation in a string, escaping quotes with backslashes and replacing the line breaks with :

{
    \"query\": \"query {\n me {\n id\n lastName\n email\n }\n }\"
}

This request requires to be authenticated, so you have to pass the OAuth access token in the HTTP header "Authorization" this way :

Authorization: Bearer {access token}

To submit the request to the API it is possible to use :

  • the console for an interactive experience. See the console guide.

  • any HTTP library (curl, pythonrequests, ...)

Via cURL

You just have to build the JSON body of the request from the query field :

curl \
  -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {access_token}" \
  --data "{ \"query\": \"query {\n me {\n id\n lastName\n email\n }\n }\"}" \
  https://api.sandbox.mobilic.beta.gouv.fr/graphql

For more information on how to write GraphQL operations you can consult our guide on GraphQL operations.

Last updated