」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 在黑客馬拉松中使用 Kintone 的技巧

在黑客馬拉松中使用 Kintone 的技巧

發佈於2024-11-08
瀏覽:611

Introduction

When you're participating in a hackathon, efficiency and quick iteration are key to success. One tool that can help you manage data efficiently is Kintone, a powerful no-code/low-code platform that allows you to create web-based databases with ease.

In this guide, we'll walk you through how to create a simple Kintone App to store scores for games, and demonstrate how to interact with the Kintone API using some local Python code.

Get your Kintone Environment

First we need to get our hands on a Kintone Environment!
Developers are entitled to use the Kintone Developer License - an environment that can be used for free for 1 year ❤

Get your Kintone Developer License by filling out the form.
https://kintone.dev/en/developer-license-registration-form/

Create your Kintone Database

Web Databases in Kintone are called "Apps".
Creating these Apps are easy in Kintone - you can drag-and-drop the fields that you need, without needing to code.

Tips for using Kintone in Hackathons

Follow the instructions on the following link to create a new App.
https://get.kintone.help/k/en/id/040133.html

These are the fields we will include in the Kintone App for this article:

Field Type Field Name Field Code
Text Player Name playername
Number Score score
Text Difficulty difficulty

The field layout should look like the following:

Tips for using Kintone in Hackathons

After that, proceed to the Settings tab, and generate an API Token that will be used for the authentication. Set the permissions for View records and Add records.

https://get.kintone.help/k/en/id/040471.html

Once this is done, save the settings, and click on the blue "Activate App" button.

Manually Input Some Data

Since there is no data yet inside the App, manually add in some data so that we have something to work with.
https://get.kintone.help/k/en/id/040715.html

Tips for using Kintone in Hackathons

Now we're ready to interact with the Web Database with some Python code!

Sample Python Code to Interact with Kintone

Now that your app is set up, let's look at how you can interact with the Kintone API using Python. We'll cover how to add a record, retrieve all records, and query records based on difficulty.

Get a Python environment ready on your local machine. Since we will be using the requests library to make our API calls, install the library with the following command:


pip install requests


1. Adding a Record to the Kintone App

Below is a sample Python script that adds a new record to the Kintone App.


import requests
import json

def add_record():
    API_endpoint = "https://{YOUR_SUBDOMAIN}.cybozu.com/k/v1/record.json"
    app_id = "{APP_ID}"

    kintone_headers = {
        "X-Cybozu-API-Token": "{API_TOKEN}",
        "Content-Type": "application/json"
    }

    bodydata = {
        "app": app_id,
        "record": {
            "player": {
                "value": "John Doe"
            },
            "score": {
                "value": "1500"
            },
            "diff": {
                "value": "Medium"
            }
        }
    }

    try:
        response = requests.post(API_endpoint, headers=kintone_headers, data=json.dumps(bodydata))
        jsondata = response.json()
        print(jsondata)

    except requests.exceptions.RequestException as error:
        print(error)

add_record()


The App ID is a number that can be found in the URL of the Kintone App.
If the request is successful, a JSON is responded that includes the ID of the newly added record.


{'id': '7', 'revision': '1'}


If the request is successful, but the record data is empty, it may be because the keys inside the body data were incorrect. Make sure that the keys for the fields are stated as their field codes, and not their field names.

2. Retrieving All Records from the Kintone App

The following Python script will retrieve all records stored in your Kintone App.


import requests

def get_all_records():
    API_endpoint = "https://{YOUR_SUBDOMAIN}.cybozu.com/k/v1/records.json"
    app_id = "{APP_ID}"
    API_endpoint = API_endpoint   "?app="   app_id

    kintone_headers = {
        "X-Cybozu-API-Token": "{API_TOKEN}",
    }

    try:
        response = requests.get(API_endpoint, headers=kintone_headers)
        jsondata = response.json()
        print(jsondata)

    except requests.exceptions.RequestException as error:
        print(error)

get_all_records()


If the request is successful, the response will include a JSON of all the records in the App.


"records": [
    {
      "difficulty": {
        "type": "DROP_DOWN",
        "value": null
      },
      "score": {
        "type": "NUMBER",
        "value": "1500"
      },
      "Record Number": {
        "type": "RECORD_NUMBER",
        "value": "7"
      },
      "Updated By": {
        "type": "MODIFIER",
        "value": {
          "code": "Administrator",
          "name": "Administrator"
        }
      },
      "Created By": {
        "type": "CREATOR",
        "value": {
          "code": "Administrator",
          "name": "Administrator"
        }
      },
      "playername": {
        "type": "SINGLE_LINE_TEXT",
        "value": ""
      },
      "$revision": {
        "type": "__REVISION__",
        "value": "1"
      },
      "Updated Datetime": {
        "type": "UPDATED_TIME",
        "value": "2024-10-06T02:33:00Z"
      },
      "Created Datetime": {
        "type": "CREATED_TIME",
        "value": "2024-10-06T02:33:00Z"
      },
      "$id": {
        "type": "__ID__",
        "value": "7"
      }
    },
    {
      "difficulty": {
        "type": "DROP_DOWN",
        "value": "Hard"
      },
      "score": {
        "type": "NUMBER",
        "value": "34000"
      },
      "Record Number": {
        "type": "RECORD_NUMBER",
        "value": "6"
      },
      "Updated By": {
        "type": "MODIFIER",
        "value": {
          "code": "will",
          "name": "will-yama"
        }
      },
      "Created By": {
        "type": "CREATOR",
        "value": {
          "code": "will",
          "name": "will-yama"
        }
      },
      "playername": {
        "type": "SINGLE_LINE_TEXT",
        "value": "Kelly Smiles"
      },
      "$revision": {
        "type": "__REVISION__",
        "value": "1"
      },
      "Updated Datetime": {
        "type": "UPDATED_TIME",
        "value": "2024-10-06T01:41:00Z"
      },
      "Created Datetime": {
        "type": "CREATED_TIME",
        "value": "2024-10-06T01:41:00Z"
      },
      "$id": {
        "type": "__ID__",
        "value": "6"
      }
    },...


We have cut off the above JSON response half way through for this article, as it is quite long.

3. Retrieving Records with Query Filtering

In some cases, you may want to retrieve records based on specific conditions, such as fetching records where the difficulty is set to "Hard". Add a query to the GET request to achieve this.


import requests

def get_all_records():
    API_endpoint = "https://{YOUR_SUBDOMAIN}.cybozu.com/k/v1/records.json"
    app_id = "{APP_ID}"
    query = "difficulty in (\"Hard\")"
    API_endpoint = API_endpoint   "?app="   app_id   "&query="   query

    kintone_headers = {
        "X-Cybozu-API-Token": "{API_TOKEN}",
    }

    try:
        response = requests.get(API_endpoint, headers=kintone_headers)
        jsondata = response.json()
        print(jsondata)

    except requests.exceptions.RequestException as error:
        print(error)

get_all_records()


If the request is successful, the response will include a JSON of the filtered records.


"records": [
{
"difficulty": {
"type": "DROP_DOWN",
"value": "Hard"
},
"score": {
"type": "NUMBER",
"value": "34000"
},
"Record Number": {
"type": "RECORD_NUMBER",
"value": "6"
},
"Updated By": {
"type": "MODIFIER",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"Created By": {
"type": "CREATOR",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"playername": {
"type": "SINGLE_LINE_TEXT",
"value": "Kelly Smiles"
},
"$revision": {
"type": "REVISION",
"value": "1"
},
"Updated Datetime": {
"type": "UPDATED_TIME",
"value": "2024-10-06T01:41:00Z"
},
"Created Datetime": {
"type": "CREATED_TIME",
"value": "2024-10-06T01:41:00Z"
},
"$id": {
"type": "ID",
"value": "6"
}
},
{
"difficulty": {
"type": "DROP_DOWN",
"value": "Hard"
},
"score": {
"type": "NUMBER",
"value": "45000"
},
"Record Number": {
"type": "RECORD_NUMBER",
"value": "5"
},
"Updated By": {
"type": "MODIFIER",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"Created By": {
"type": "CREATOR",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"playername": {
"type": "SINGLE_LINE_TEXT",
"value": "Jay Pudding"
},
"$revision": {
"type": "REVISION",
"value": "1"
},
"Updated Datetime": {
"type": "UPDATED_TIME",
"value": "2024-10-06T01:38:00Z"
},
"Created Datetime": {
"type": "CREATED_TIME",
"value": "2024-10-06T01:38:00Z"
},
"$id": {
"type": "ID",
"value": "5"
}
},
{
"difficulty": {
"type": "DROP_DOWN",
"value": "Hard"
},
"score": {
"type": "NUMBER",
"value": "34000"
},
"Record Number": {
"type": "RECORD_NUMBER",
"value": "2"
},
"Updated By": {
"type": "MODIFIER",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"Created By": {
"type": "CREATOR",
"value": {
"code": "will",
"name": "William Sayama"
}
},
"playername": {
"type": "SINGLE_LINE_TEXT",
"value": "Jam Flipping"
},
"$revision": {
"type": "REVISION",
"value": "2"
},
"Updated Datetime": {
"type": "UPDATED_TIME",
"value": "2024-10-06T01:38:00Z"
},
"Created Datetime": {
"type": "CREATED_TIME",
"value": "2024-10-05T01:26:00Z"
},
"$id": {
"type": "ID",
"value": "2"
}
}
],
"totalCount": null




Conclusion

By setting up a Kintone App and interacting with it via API, you can easily manage data for your projects. Whether you're keeping track of player performances or storing other types of data, Kintone’s flexible API makes it easy to integrate into any hackathon project.

This guide has provided examples for adding records, retrieving all records, and querying records with specific conditions, allowing you to customize your data management according to your needs.

Good luck at your hackathon, and happy coding with Kintone!

版本聲明 本文轉載於:https://dev.to/kintonedevprogram/tips-for-using-kintone-in-hackathons-3j90?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • 您可以將內聯腳本與 JavaScript 中的「src」屬性結合嗎?
    您可以將內聯腳本與 JavaScript 中的「src」屬性結合嗎?
    JavaScript 中具有SRC 屬性的內聯腳本在JavaScript 中,通常使用 標籤包含腳本,其中src 屬性指定外部腳本檔案。然而,有時會想知道是否可以將內聯腳本與 src 屬性組合起來。 規則官方行為受 HTML 4.01 規範管轄,該規範聲明 src 屬性優先於 標記的主體。這意味著...
    程式設計 發佈於2024-11-08
  • 不可變資料結構:ECMA 4 中的記錄和元組
    不可變資料結構:ECMA 4 中的記錄和元組
    不可變資料結構:ECMAScript 2024 中的新功能 ECMAScript 2024 引入了幾個令人興奮的更新,但對我來說最突出的一個功能是引入了不可變資料結構。這些新結構——記錄和元組——改變了 JavaScript 中資料管理的遊戲規則。它們提供了一種令人滿意的方式來保持...
    程式設計 發佈於2024-11-08
  • 如何在 PHP 中為註冊用戶自訂 URL?
    如何在 PHP 中為註冊用戶自訂 URL?
    在PHP 中為註冊用戶設定自訂URL對於電子商務平台來說,為每個用戶提供唯一的URL 對於展示他們的產品至關重要單獨的產品。透過產生單獨的網址(例如 www.seloncart.com/customername),您可以顯示客戶的特定產品。為此,請按照下列步驟操作:設定伺服器路由: 修改伺服器設定以...
    程式設計 發佈於2024-11-08
  • 我如何用 Python 建立 QR 碼產生器
    我如何用 Python 建立 QR 碼產生器
    這將是一篇簡短的文章,介紹我如何在 Python 中建立一個簡單的二維碼產生器 對於此步驟,您需要使用 qrcode 函式庫:https://pypi.org/project/qrcode/ 建立專案資料夾後我所做的第一步就是建立一個虛擬環境。 Python 中的虛擬環境只是電腦上另一個獨立的工作區...
    程式設計 發佈於2024-11-08
  • 如何在 PHP 中驗證整數資料型態?
    如何在 PHP 中驗證整數資料型態?
    在驗證 PHP 中的整數資料類型在 PHP 中處理數位資料時,確定變數是否表示整數至關重要。為了解決這個問題,通常會使用 is_int() 函數。然而,它的行為有時可能是意想不到的,導致混亂。 為了修正這個問題,我們引入了驗證整數資料型別的替代方法:FILTER_VALIDATE_INT使用該方法,...
    程式設計 發佈於2024-11-08
  • 為什麼 DOMSubtreeModified 在 DOM Level 3 中被棄用以及替代方案是什麼?
    為什麼 DOMSubtreeModified 在 DOM Level 3 中被棄用以及替代方案是什麼?
    在DOM Level 3 中棄用DOMSubtreeModified 事件DOMSubtreeModified 事件曾經是跟踪文檔子樹中更改的基本元素,現在已被跟踪在DOM level 3 中已過時。了解這種棄用背後的基本原理並確定合適的替代方案至關重要。 DOM Level 3 規範對 DOMSu...
    程式設計 發佈於2024-11-08
  • 將 PDO 連線設為 NULL 是否真正關閉連線並釋放資源?
    將 PDO 連線設為 NULL 是否真正關閉連線並釋放資源?
    關閉PDO連線在PHP中,有兩種​​流行的資料庫連線介面:MySQLi和PDO。雖然兩者的用途相似,但它們處理連接關閉的方式不同。 MySQLi 需要明確關閉函數呼叫來釋放連接:$this->connection->close();相反,PDO 使用空賦值來終止連線:$this->...
    程式設計 發佈於2024-11-08
  • 動態資料管理:了解 Vue.js 中的資料屬性
    動態資料管理:了解 Vue.js 中的資料屬性
    Vue.js 是用於開發現代 Web 應用程式的最受歡迎的 JavaScript 框架之一。它提供了一種創建互動式動態應用程式的有效方法。在本文中,我們將深入研究 Vue.js 中的 data 屬性,並探討它的工作原理、為什麼要使用它以及圍繞它的最佳實踐。 什麼是資料屬性? 在Vu...
    程式設計 發佈於2024-11-08
  • 如何有效地檢查 Python 字串中是否存在列表元素?
    如何有效地檢查 Python 字串中是否存在列表元素?
    檢查Python 中字串中清單元素的存在Python 程式設計中的一個常見任務是驗證字串是否包含給定的元素列表。傳統方法採用 for 循環,如下面的程式碼所示:extensionsToCheck = ['.pdf', '.doc', '.xls'] for extension in extensio...
    程式設計 發佈於2024-11-08
  • \'window.JSON\' 如何在現代瀏覽器中提供本機 JSON 支援?
    \'window.JSON\' 如何在現代瀏覽器中提供本機 JSON 支援?
    瀏覽器原生JSON 支援:window.JSON 物件瀏覽器原生JSON 支援:window.JSON 物件window.JSON 物件為現代Web 瀏覽器提供原生JSON 解析與序列化功能,實現結構化資料的高效能、安全處理。本文探討了該物件的詳細信息,包括其支援的方法和瀏覽器相容性。 window...
    程式設計 發佈於2024-11-08
  • Java 中的介面繼承自物件類別嗎?
    Java 中的介面繼承自物件類別嗎?
    介面與物件類別:繼承與方法呼叫在Java 中,介面提供了一種定義類別可以實現的契約的方法。在考慮介面和Object類別的關係時,就提出了繼承的問題。 介面是否繼承自Object類別? 答案是否。介面不繼承自Object 類別。與類別不同,所有介面都不會隱式繼承任何公共根介面。 介面實例上的方法呼叫儘...
    程式設計 發佈於2024-11-08
  • Python:有趣的程式碼模式
    Python:有趣的程式碼模式
    我主要使用 Python 工作,幾乎每天都會檢查程式碼。在我們的程式碼庫中,格式化和 linting 由 CI 作業使用 black 和 mypy 處理。因此,我們只關注變化。 在團隊中工作時,您已經知道某個團隊成員會寫什麼樣的程式碼。當新人加入團隊時,程式碼審查會變得有趣。我說有趣,是因為每個人...
    程式設計 發佈於2024-11-08
  • 在 Laravel 中使用 Redis 進行快取:逐步指南
    在 Laravel 中使用 Redis 進行快取:逐步指南
    Introduction Laravel is, without fear of contradiction, the most popular PHP framework, and among the most popular within web development. Re...
    程式設計 發佈於2024-11-08
  • 釋放即時 UI 的力量:使用 React.js、gRPC、Envoy 和 Golang 串流資料的初學者指南
    釋放即時 UI 的力量:使用 React.js、gRPC、Envoy 和 Golang 串流資料的初學者指南
    作者:Naveen M 背景 作为 Kubernetes 平台团队的一部分,我们面临着提供用户工作负载实时可见性的持续挑战。从监控资源使用情况到跟踪 Kubernetes 集群活动和应用程序状态,每个特定类别都有许多开源解决方案。然而,这些工具往往分散在不同的平台上,导致用户体验支离...
    程式設計 發佈於2024-11-08

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3