action.skip

Getting Started with API

Description: Get started with integrating Flotiq API into your application.

Before you begin, make sure you have the following:

  • Flotiq Account: Sign up for an account on Flotiq website if you haven't already.
  • Content Types: Make sure you have already created the necessary Content Type Definitions in your Flotiq account. It should contain at least one Content Object.
  • API Key: Obtain your Application Read and Write API Key from the Flotiq dashboard. You'll need it to perform API operations.
  • Basic understanding of RESTful APIs: Familiarize yourself with the concepts of RESTful APIs if you're new to this.

Step 1: Implementing API Integration

Once you have your Content Type Definitions ready, you can proceed with integrating Flotiq API into your application. Here's a high-level overview of the steps involved:

  • Authentication: Use your API key to authenticate API requests. Include the key in the request headers or as a query parameter, depending on the API endpoint.
  • Data Manipulation: Perform CRUD operations (Create, Read, Update, Delete) on your Content Types using the appropriate API endpoints and HTTP methods.
  • Handling Responses: Handle the API responses in your application code to process the data returned by the API and handle errors gracefully.
  • Testing and Debugging: Use tools like CURL or Postman to test your API requests and ensure they are working as expected.
  • Best Practices: Follow best practices for API integration, such as using pagination for large result sets, implementing caching mechanisms, and handling rate limits.

Flotiq provides two options for retrieving data: REST API and GraphQL. Here's an overview of the steps involved:

For REST API:

Retrieve the schema of a specific Content Object by sending a GET request to the https://api.flotiq.com/api/v1/content/{name}/{id} endpoint. Check the documentation for more details.

Example

curl --location --request GET "https://api.flotiq.com/api/v1/content/blogposts/blogposts-456712" \
--header "accept: application/json" \
--header "X-AUTH-TOKEN: YOUR_API_TOKEN"

var client = new RestClient("https://api.flotiq.com/api/v1/content/blogpostsblogposts-456712");
var request = new RestRequest(Method.GET);
request.AddHeader("X-AUTH-TOKEN", "YOUR_API_KEY");
IRestResponse response = client.Execute(request);

package main

import (
    "fmt"
    "net/http"
    "io/ioutil"
)

func main() {

    url := "https://api.flotiq.com/api/v1/content/blogpostsblogposts-456712"

    req, _ := http.NewRequest("GET", url, nil)

    req.Header.Add("X-AUTH-TOKEN", "YOUR_API_KEY")

    res, _ := http.DefaultClient.Do(req)

    defer res.Body.Close()
    body, _ := ioutil.ReadAll(res.Body)

    fmt.Println(res)
    fmt.Println(string(body))

}

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
    .url("https://api.flotiq.com/api/v1/content/blogpostsblogposts-456712")
    .get()
    .addHeader("X-AUTH-TOKEN", "YOUR_API_KEY")
    .build();

Response response = client.newCall(request).execute();

HttpResponse<String> response = Unirest.get("https://api.flotiq.com/api/v1/content/blogpostsblogposts-456712")
    .header("X-AUTH-TOKEN", "YOUR_API_KEY")
    .asString();

const request = require('request');

const options = {
    method: 'DELETE',
    url: 'https://api.flotiq.com/api/v1/content/blogposts/blogposts-456712',
    headers: {'X-AUTH-TOKEN': 'YOUR_API_KEY'},
};

request(options, function (error, response, body) {
    if (error) throw new Error(error);

    console.log(body);
});

<?php

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.flotiq.com/api/v1/content/blogposts/blogposts-456712",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "DELETE",
    CURLOPT_HTTPHEADER => [
            "X-AUTH-TOKEN: YOUR_API_KEY",
        ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

Response

Returned when the object was found

{
  "id": "blogposts-456712",
    "internal": {
        "contentType": "blogposts",
        "createdAt": "2021-04-09T13:30:48+00:00",
        "updatedAt": "2021-04-09T13:30:48+00:00",
        "deletedAt": ""
    },
    "title": "New object",
    "postContent": "This will be the new <b>content</b>"
  }
}

Returned when API key was missing or incorrect

{
    "code": 401,
    "massage": "Unauthorized"
}

Returned when content type definition wasn't found

{
    "code": 404,
    "massage": "Not found"
}

For GraphQL:

Flotiq supports GraphQL queries for Content Objects. You can use the following endpoints to interact with the system using GraphQL:

  • GET /api/graphql/schema - Retrieve the GraphQL schema that describes your data.
  • POST /api/graphql - Execute GraphQL queries to retrieve specific data.

To a get single object, you need to pass the object identifier and fields you want to receive in the response. Example Query in GraphQL language to get id and title for the product with id blogposts-456712 looks like:

Graphql

query {
    blogposts(id:"blogposts-456712") {
        id
        title
    }
}

To pass this query to the Flotiq, you need to call:

Example

curl -X POST 'https://api.flotiq.com/api/graphql' \
--header 'X-AUTH-TOKEN: YOUR_API_TOKEN' \
--header 'Content-Type: application/json' \
--data-raw '{"query":"query { blogposts(id: \"blogposts-456712\") { id title } }"}'

fetch('https://api.flotiq.com/api/graphql', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'X-AUTH-TOKEN': 'YOUR_API_TOKEN'
    },
    body: JSON.stringify({
        query: 'query { blogposts(id: "blogposts-456712") { id title } }'
    })
})
.then(response => response.json())
.then(data => console.log(data));

const axios = require('axios');

axios.post('https://api.flotiq.com/api/graphql', {
    query: 'query { blogposts(id: "blogposts-456712") { id title } }'
}, {
    headers: {
        'Content-Type': 'application/json',
        'X-AUTH-TOKEN': 'YOUR_API_TOKEN'
    }
})
.then(response => console.log(response.data))
.catch(error => console.log(error));

import requests

url = 'https://api.flotiq.com/api/graphql'
headers = {
    'Content-Type': 'application/json',
    'X-AUTH-TOKEN': 'YOUR_API_TOKEN'
}
data = {
    'query': 'query { blogposts(id: "blogposts-456712") { id title } }'
}

response = requests.post(url, headers=headers, json=data)
print(response.json())

Response

Returned when the object was found

{
    "data": {
        "blogposts": {
            "id": "blogposts-456712",
            "title": "New object"
        }
    }
}

Returned when the API key was missing or incorrect

{
    "errors": [
        {
            "message": "Unauthorized",
            "extensions": {
                "code": "UNAUTHORIZED"
            }
        }
    ]
}

Returned when the content type definition wasn't found

{
    "errors": [
        {
            "message": "Not found",
            "extensions": {
                "code": "NOT_FOUND"
            }
        }
    ]
}

Step 2: Exploring Advanced Features

Flotiq API offers various advanced features and functionalities to enhance your application. Here are a few examples:

  • Search: Perform advanced search queries to retrieve specific data from your Content Types.
  • Media Management: Upload and manage media assets such as images and videos in your application.

Congratulations! You now have a basic understanding of integrating Flotiq API into your application. Start by creating your Content Type Definitions and then follow the API integration steps to build powerful applications using Flotiq. If you need further assistance, refer to the specific sections in the documentation or reach out to our support team.