Apillon Features: API calls to Web3 services
Published: 2023-03-20 13:42:54

---
title: Apillon Features: API calls to Web3 services
published: true
description: Apillon API delivers a straightforward connectivity to Polkadot parachains while respecting the standard development workflow.
tags: 
# cover_image: https://direct_url_to_image.jpg
# Use a ratio of 100:42 for best results.
# published_at: 2023-03-20 11:42 +0000
---

*Apillon API delivers a straightforward connectivity to Polkadot parachains while respecting the standard development workflow.*

---

One of the main hinderers of Web3 adoption is the development process. Apillon API shortens the way Web3 products are built by saving developers the trouble of diving into each parachain's specifics, logic, and requirements.

## The drawbacks of standard access to Web3

If you decide to code a Web3 project or implement a decentralized service provider to your existing website or app from scratch, you face a steep learning curve and a potentially high risk of things going south.

Wrestling with Web3 bare-handed could be extremely heavy on resources while still not guaranteeing any wins. There are plenty of uncertainties along the way, and every developer, even the Web3 veterans, could easily overlook important steps, ultimately leading to deep frustration and even abandonment of the Web3 mission altogether.

> 🔎 *[Learn more about the challenges of building on Web3](https://blog.apillon.io/how-apillon-changes-the-way-web3-products-are-built-ee0adae9b94a).*

To simplify the development process and bring it to terms every developer should be familiar with, Apillon introduces API connectivity to linked Polkadot parachains and their Web3 services.

## Apillon Web3 APIs

Apillon integrates multiple [Polkadot](https://polkadot.network/) parachains and offers straightforward access to linked decentralized services in two ways:

* A drag-and-drop deployment of [Web3 services](https://blog.apillon.io/apillon-platform-up-close-web3-services-f77530dd274e) on the Apillon dashboard
* API keys

In this post, we will dive into the latter, where Apillon APIs enhance and streamline the coding process of Web3 projects.

### What is Apillon API?

Apillon API is a set of RESTful API endpoints that allow you to integrate Apillon Web3 services modules into your Web3 project.

Using Apillon APIs, you make a call to a server and receive the response over the HTTP protocol.

To ensure the privacy and safety of Web3 project development, all routes are private and require you to use an API key.

Now, let's see how to use Apillon APIs when coding your Web3 project.

### Apillon API specifics

**Requests**
The server speaks [JSON](https://en.wikipedia.org/wiki/JSON), and for that reason, every call to the server should include a `Content-Type` header set to `application/json;`.

**Authentication and authorization**
Apillon API routes ensure privacy by restricting public access and requiring authentication.

When creating requests, you should therefore include a [basic auth](https://en.wikipedia.org/wiki/Basic_access_authentication) HTTP header field in the form of `Authorization: Basic <credentials>`, where credentials represent the Base64 encoding of API key and API key secret joined by a single colon `:`.

You can generate API keys on the [Apillon dashboard](https://app.apillon.io/dashboard/api-keys) under Project settings.

![apillon-dashboard-api-key-generation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4enuve8ro6bqgv5u2zdo.png)
![apillon-dashboard-api-key-details](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3wwvbdsdc124c1m87ofh.png)

Once generated, you can use the API key in your project.

**Responses**
Every response has a unique ID to help you identify potential issues in the API connectivity or accessed services. It also includes a status code so you can quickly identify the cause of a potential problem.

Query requests through `GET` method can return status codes `200`, `400`, `401`, `403`, or `500`, indicating success, bad request, unauthenticated or unauthorized access, or system error.

Mutations through `POST`, `PUT` and `DELETE` can further return codes `201` and `422`, namely successful creation or failed data validation. And, invalid routes return status code `404`, indicating path not found.

A successful request includes a `data` key, which holds a valid response object.

> 🔎 *Learn more about Apillon Web3 API, responses, error handling, and validation in [Apillon Wiki](https://wiki.apillon.io/build/3-apillon-api.html).*

![apillon-api-to-web3-wiki](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9932gy2ni7meaaujgzvk.gif)

Now with theory out of the way, let's dive into the contents of APIs connecting to the two Web3 services accessible in the Apillon Beta:

* Web3 Storage API
* Web3 Hosting API

> ☝️ *More APIs will be made available in the upcoming versions of the Apillon platform, so [stay tuned](https://twitter.com/apillon).*

## Web3 Storage API

Apillon Web3 Storage API connects to the [Crust Network](https://www.crust.network/), allowing you to store your files in a decentralized way.

Before you start using the Web3 Storage API, there are two things to keep in mind:
* You should first create a [storage bucket](https://wiki.apillon.io/build/2-web3-services.html#storage-bucket) on the [Apillon dashboard](https://app.apillon.io/login).
* In all cURL examples, parameters with a colon as a prefix should be replaced with real values.

### File upload process via Apillon Web3 Storage API

The files you store on the Crust Network are uploaded as follows:
1. Request signed URL(s) for upload.
2. File is uploaded to Apillon central server.
3. File is transferred to IPFS and available through the Apillon gateway.
4. File is replicated to different IPFS nodes globally via Crust Network.

Now, let's do it step by step using Apillon API.

### How to use Apillon Web3 Storage API

**1. Upload to storage bucket**
First, create file upload requests that return URLs for file upload along with `sessionUuid`.

🔻 cURL

```javascript
curl --location --request POST "https://api.apillon.io/storage/:bucketUuid/upload" \
--header "Authorization: Basic :credentials" \
--header "Content-Type: application/json" \
--data-raw "{
    \"files\": [
        {
            \"fileName\": \"My test file\",
            \"contentType\": \"text/html\"
        }
    ]

}"
```

🔻 Response

```javascript
{
  "id": "cbdc4930-2bbd-4b20-84fa-15daa4429952",
  "status": 201,
  "data": {
    "sessionUuid": "3b6113bc-f265-4662-8cc5-ea86f06cc74b",
    "files": [
      {
        "path": null,
        "fileName": "My test file",
        "contentType": "text/html",
        "url": "https://sync-to-ipfs-queue.s3.eu-west-1.amazonaws.com/STORAGE_sessions/73/3b6113bc-f265-4662-8cc5-ea86f06cc74b/My%20test%20file?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAQIMRRA6GJRL57L7G%2F20230215%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20230215T114524Z&X-Amz-Expires=900&X-Amz-Signature=499367f6c6bff5be50686724475ac2fa6307b77b94fd1a25584c092fe74b0a58&X-Amz-SignedHeaders=host&x-id=PutObject",
        "fileUuid": "4ef1177b-f7c9-4434-be56-a559cec0cc18"
      }
    ]
  }
}
```

**2. End upload session**
Once files are uploaded to the cloud server via the received URL, trigger file sync to IPFS and Crust.

🔻 cURL

```javascript
curl --location --request POST "https://api.apillon.io/storage/:bucketUuid/upload/:sessionUuid/end" \
--header "Authorization: Basic :credentials" \
--header "Content-Type: application/json" \
--data-raw "{
    \"directSync\": true
}"
```

🔻 Response

```javascript
{
  "id": "b64b1c07-1a8a-4b05-9e3b-3c6a519d6ff7",
  "status": 200,
  "data": true
}
```

**3. Get bucket content**
Next, get directories and files in the storage bucket. Note that items are paginated and can be filtered and ordered through query parameters.

🔻 cURL basic

```javascript
curl --location --request GET "https://api.apillon.io/storage/:bucketUuid/content" \
--header "Authorization: Basic :credentials"
```

🔻 cURL with params

```javascript
curl --location --request GET "https://api.apillon.io/storage/:bucketUuid/content?orderBy=name&desc=false&limit=5&page=1" \
--header "Authorization: Basic :credentials"
```

🔻 Response

```javascript
{
    "id": "c8c50b3b-91ff-42c7-b0af-f866ce23f18a",
    "status": 200,
    "data": {
        "items": [
            ...
            {
                "type": 1,
                "id": 11,
                "status": 5,
                "name": "My directory",
                "CID": null,
                "createTime": "2022-12-08T13:27:00.000Z",
                "updateTime": "2023-01-10T12:18:55.000Z",
                "contentType": null,
                "size": null,
                "parentDirectoryId": null,
                "fileUuid": null,
                "link": null
            },
            {
                "type": 2,
                "id": 397,
                "status": 5,
                "name": "My file.txt",
                "CID": "QmcG9r6Rdw9ZdJ4imGBWc6mi5VzWHQfkcLDMe2aP74eb42",
                "createTime": "2023-01-19T10:10:01.000Z",
                "updateTime": "2023-01-19T10:10:31.000Z",
                "contentType": "text/plain",
                "size": 68,
                "parentDirectoryId": null,
                "fileUuid": "0a775bfa-a0d0-4e0b-9a1e-e909e426bd11",
                "link": "https://ipfs.apillon.io/ipfs/QmcG9r6Rdw9ZdJ4imGBWc6mi5VzWHQfkcLDMe2aP74eb42"
            }
            ...
        ],
        "total": 10
    }
}
```

**4. Get file details**
Lastly, get details of a specific file inside a storage bucket.

🔻 cURL

```javascript
curl --location --request GET "https://api.apillon.io/storage/:bucketUuid/file/:id/detail" \
--header "Authorization: Basic :credentials"
```

🔻 Response

```javascript
{
  "id": "5be33c54-2cc9-46f4-8f50-debc98866810",
  "status": 200,
  "data": {
    "fileStatus": 4,
    "file": {
      "id": 397,
      "status": 5,
      "fileUuid": "0a775bfa-a0d0-4e0b-9a1e-e909e426bd11",
      "CID": "QmcG9r6Rdw9ZdJ4imGBWc6mi5VzWHQfkcLDMe2aP74eb42",
      "name": "My file.txt",
      "contentType": "text/plain",
      "size": 68,
      "fileStatus": 4,
      "downloadLink": "https://ipfs.apillon.io/ipfs/QmcG9r6Rdw9ZdJ4imGBWc6mi5VzWHQfkcLDMe2aP74eb42"
    }
  }
}
```

That's it, your files should now be stored on Crust Network.

**5. Delete file**
To delete a file, you can mark it for deletion inside a storage bucket using `id`, `fileUuid`, or `CID`. The file will be completely deleted from the Apillon system and Apillon IPFS node after three months. Once a file is marked for deletion, it will not be renewed on Crust Network.

🔻 cURL

```javascript
curl --location --request DELETE "https://api.apillon.io/storage/:bucketUuid/file/:id" \
--header "Authorization: Basic :credentials" \
--data-raw ""
```

🔻 Response

```javascript
{
  "id": "bc92ff8d-05f2-4380-bb13-75a1b6b7f388",
  "status": 200,
  "data": {
    "id": 397,
    "status": 8,
    "fileUuid": "0a775bfa-a0d0-4e0b-9a1e-e909e426bd11",
    "CID": "QmcG9r6Rdw9ZdJ4imGBWc6mi5VzWHQfkcLDMe2aP74eb42",
    "name": "My file.txt",
    "contentType": "text/plain",
    "size": 68,
    "fileStatus": 4
  }
}
```

Voila, you've made it through the whole process of uploading files to decentralized storage via Crust Network and Apillon API.

> 🔎 *Dive into more details, parameters, metadata, and statuses of the [Web3 Storage API](https://wiki.apillon.io/build/3-apillon-api.html#web3-storage-api) and connect Crust Network's decentralized storage service to your website or app.*

![apillon-web3-storage-api-wiki](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fumfphbuglpulbr64y66.gif)

## Web3 Hosting API

Apillon Web3 Hosting API connects to the [Crust Network](https://www.crust.network/), where you can host your website in a decentralized way.

Before you start using the Web3 Hosting API, there are two things to keep in mind:
* You should first create a website on the [Apillon dashboard](https://app.apillon.io/dashboard/service/hosting).
* In all cURL examples, parameters with a colon as a prefix should be replaced with real values.

### Website deployment process via Apillon Web3 Hosting API

Apillon Hosting API provides endpoints that can be used to implement [CI/CD](https://en.wikipedia.org/wiki/CI/CD).

The website you host on the Crust Network is deployed as follows:
1. Website files are uploaded to the Apillon cloud server.
2. Request URLs for files upload.
3. Files are uploaded to a cloud server.
4. Trigger transfer to website.
5. Deployment to staging or production environment.

Now, let's do it step by step using Apillon API.

### How to use Apillon Web3 Hosting API

**1. Get URLs for files upload**
First, create file upload requests that return URLs for file upload.

🔻 cURL

```javascript
curl --location --request POST "https://api.apillon.io/hosting/websites/:websiteUuid/upload" \
--header "Authorization: Basic :credentials" \
--header "Content-Type: application/json" \
--data-raw "{
    \"files\": [
        {
            \"fileName\": \"index.html\",
            \"contentType\": \"text/html\"
        },
        {
            \"fileName\": \"styles.css\",
            \"contentType\": \"text/css\",
            \"path\": \"assets/\"
        }

    ]

}"
```

🔻 Response

```javascript
{
  "id": "7dd011ec-20e2-4c28-b585-da6c6f7fce8d",
  "status": 201,
  "data": {
    "sessionUuid": "29ef6ca2-b171-440c-b934-db8aa88c3424",
    "files": [
      {
        "path": null,
        "fileName": "index.html",
        "contentType": "text/html",
        "url": "https://sync-to-ipfs-queue.s3.eu-west-1.amazonaws.com/HOSTING_sessions/70/29ef6ca2-b171-440c-b934-db8aa88c3424/index.html?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAQIMRRA6GJRL57L7G%2F20230215%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20230215T105030Z&X-Amz-Expires=900&X-Amz-Signature=187035d2307bc089101eff3abbdd7baa3e8691b4d5d3bafa5aebb87e589e8c0c&X-Amz-SignedHeaders=host&x-id=PutObject",
        "fileUuid": "e17436a1-5292-4380-ad91-eaac02a862b1"
      },
      {
        "path": "assets/",
        "fileName": "styles.css",
        "contentType": "text/css",
        "url": "https://sync-to-ipfs-queue.s3.eu-west-1.amazonaws.com/HOSTING_sessions/70/29ef6ca2-b171-440c-b934-db8aa88c3424/assets/styles.css?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAQIMRRA6GJRL57L7G%2F20230215%2Feu-west-1%2Fs3%2Faws4_request&X-Amz-Date=20230215T105030Z&X-Amz-Expires=900&X-Amz-Signature=f91b03a951fe3f99291802306be3e79812ca64e39effbb7dea1c19bb7cd1e42b&X-Amz-SignedHeaders=host&x-id=PutObject",
        "fileUuid": "358c2942-4ced-421e-9a6f-edbf94c55dff"
      }
    ]
  }
}
```

**2. End upload session**
Now, transfer files to the website storage bucket, which is used as a source for deployment to a staging (preview) environment.

🔻 cURL

```javascript
curl --location --request POST "https://api.apillon.io/hosting/websites/:websiteUuid/upload/:sessionUuid/end" \
--header "Authorization: Basic :credentials" \
--header "Content-Type: application/json" \
--data-raw "{
    \"directSync\": true
}"
```

🔻 Response

```javascript
{
  "id": "b64b1c07-1a8a-4b05-9e3b-3c6a519d6ff7",
  "status": 200,
  "data": true
}
```

**3. Deploy website**
Next, utilize endpoint to trigger website deployment into specific a environment.

🔻 cURL

```javascript
curl --location --request POST "https://api.apillon.io/hosting/websites/:websiteUuid/deploy" \
--header "Authorization: Basic :credentials" \
--header "Content-Type: application/json" \
--data-raw "{
    \"environment\": 1
}"
```

🔻 Response

```javascript
{
  "id": "32eff81a-6b0b-4a92-a5cb-e5cebf6d6c28",
  "status": 200,
  "data": {
    "id": 51,
    "status": 5,
    "websiteId": 4,
    "bucketId": 62,
    "environment": 1,
    "deploymentStatus": 0,
    "cid": null,
    "size": null,
    "number": 11
  }
}
```

**4. Get deployment**
Now, trigger endpoint to initiate deployment.

🔻 cURL

```javascript
curl --location --request GET "https://api.apillon.io/hosting/websites/:websiteUuid/deployments/:deploymentId" \
--header "Authorization: Basic :credentials"
```

🔻 Response

```javascript
{
  "id": "2d7d1b0c-15b1-4816-9aec-857182c7b617",
  "status": 200,
  "data": {
    "id": 51,
    "status": 5,
    "bucketId": 62,
    "environment": 1,
    "deploymentStatus": 10,
    "cid": "QmY3KF4F6Ap5HbrwWpq8dTVaR65Cd674jYXKBayNynDASJ",
    "size": 289,
    "number": 11
  }
}
```

**5. Get website**
Finally, get your website by triggering the endpoint to return basic website data, along with IPNS links.

🔻 cURL

```javascript
curl --location --request GET "https://api.apillon.io/hosting/websites/:websiteUuid" \
--header "Authorization: Basic :credentials"
```

🔻 Response

```javascript
{
  "id": "0eb223ce-51c0-4a9b-96ce-331a1cd99603",
  "status": 200,
  "data": {
    "id": 4,
    "status": 5,
    "name": "My test page",
    "description": null,
    "domain": "",
    "bucketUuid": "57aef0fc-84cb-4564-9af2-0f7bfc0ef729",
    "ipnsStagingLink": "https://ipfs.apillon.io/ipns/k2k4r8p6fvcyq5qogaqdtvmqn5vyvyy3khut1llkrz13ls16ocp4gojx",
    "ipnsProductionLink": "https://ipfs.apillon.io/ipns/k2k4r8ng8nqexubrmbwnhsuu1d6n4ebgnxsbdcu9gxk8uv3l67098hge"
  }
}
```

That's it, in just a few steps, you have upgraded your website's hosting to a decentralized level.

> 🔎 *Dive into specifics of [Web3 Hosting API](https://wiki.apillon.io/build/3-apillon-api.html#web3-hosting-api) and connect with Crust Network's decentralized storage to host your website or app.*

![apillon-web3-hosting-api-wiki](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jhxgerxjlmeblrukykav.gif)

## Web3 access the APIllon way

Apillon API provides straightforward connectivity to Polkadot parachain services while respecting the standard development workflow.

By accessing Web3 services via APIs, you can launch your Web3 project faster and with hardly anything to break since you control all the code.

[Let us know](https://discord.gg/yX3gTw36C4) how you find Apillon APIs and build away!

[![apillon-go-to-wiki-cta](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8vco5ndg41yb6ssg2lue.png)](https://wiki.apillon.io/build/)
[![apillon-proceed-to-dashboard-cta](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/im1y2bkeuep1ga6luj4z.png)](https://app.apillon.io/login)

---

*This post was originally published on [Apillon Medium](https://blog.apillon.io/apillon-features-api-calls-to-web3-services-c99ab6379b03).*