0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Fivetran APIでユーザーを新規作成する

Last updated at Posted at 2024-02-18

Fivetran APIを使ってユーザーを追加する方法をまとめました。

スクリーンショット 2024-02-18 12.50.50.png

POSTするエンドポイント

POST https://api.fivetran.com/v1/users

リファレンスを参考に次のユーザー情報を送ります。

{
    "given_name": "John",
    "family_name": "White",
    "email": "john.white@mycompany.com",
    "phone": "+1234567890",
    "picture": "http://mycompany.com/avatars/john_white.png",
    "role": "Account Reviewer"
}

以下3点が必須項目です。
ユーザーを作成するときには必要です。

  • emial
  • given_name
  • family_name

BashとPowerShellもどちらでも検証してみましょう。

Bashスクリプト

# FivetranのAPIキーとシークレットを設定
API_KEY="xxxxxxxxx"
API_SECRET_KEY="xxxxxxxxxxxxxxxxx"

# APIエンドポイント
URL="https://api.fivetran.com/v1/users"

# リクエストボディ
BODY='{
  "given_name": "John",
  "family_name": "White",
  "email": "john.white@mycompany.com",
  "phone": "+1234567890",
  "picture": "http://mycompany.com/avatars/john_white.png",
  "role": "Account Reviewer"
}'

# APIリクエストの実行
curl -X POST "$URL" \
     -u "$API_KEY:$API_SECRET_KEY" \
     -H "Content-Type: application/json" \
     -d "$BODY" | jq

オプションの説明

  • X:POSTを使うときに指定する
  • u:Basic認証をする。今回はAPIを使うのでキーとシークレットーキーを指定する
  • H:ヘッダー情報 リクエストボディがJSON形式であることを指定する
  • d:リクエストボディを指定する

実行結果

スクリーンショット 2024-02-18 12.54.32.png

実行が成功しました。
Fivetranダッシュボードを見てみましょう。

スクリーンショット 2024-02-18 12.55.21.png

新しいユーザーがいます。
これで寂しくありませんね!

PowerShellスクリプト

先ほど白を追加したので次は黒を追加します。

# APIキーとシークレットの設定
$apiUser = "edJXQepNpzFNV9xv"
$apiSecret = "zzt64Mhh4QebmY0E7sVRGMrCtoE2Azqs"

# Base64でエンコード
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $apiUser, $apiSecret)))

# ヘッダーの準備
$headers = @{
    "Authorization" = "Basic $base64AuthInfo"
    "Content-Type" = "application/json"
}

# APIエンドポイント
$url = "https://api.fivetran.com/v1/users"

# リクエストボディ
$body = @{
    given_name = "John"
    family_name = "black"
    email = "john.black@mycompany.com"
    phone = "+1234567890"
    picture = "http://mycompany.com/avatars/john_black.png"
    role = "Account Reviewer"
} | ConvertTo-Json

# APIリクエストの実行
$response = Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body -AllowInsecureRedirect

# レスポンスの表示
$response

実行結果

スクリーンショット 2024-02-18 13.00.55.png

成功しました。
ダッシュボードを確認してもいますね!

スクリーンショット 2024-02-18 13.02.12.png

まとめ

今回はFivetran APIを使ってユーザーを追加しました。

Fivetran APIではユーザーを作成する以外に、コネクタ(Connector)やディスティネーション(Destination)も作成ができます。

詳しくはFivetranとは?Fivetran APIの使い方と各種設定方法を紹介で紹介しているのでぜひご覧ください!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?