API Driver の API プロファイルを編集する



RESTful API は、企業が外部データを扱い、自社データへのアクセスを提供するための一貫性のある直感的な手段を提供します。2019年6月時点で、パブリック API の数は22,000を超え、2015年以降は年間2,000以上のペースで増加し続けています。API は組織や開発者に価値を提供し続けており、CData API Driver を使用することで、これまで以上に簡単に API と連携できるようになりました。

API Driver を使用するメリット

CData API Driver は、すべての CData ドライバー と同じ目標、つまりデータ統合プロセスの簡素化を目的として構築されています。API Driver と利用可能な API プロファイルを使用すると、BI、データ統合、カスタムアプリケーションから数多くの API(CData API Server で構築された API を含む)に対して、コードを書かずに即座にクエリを実行できます。拡張可能な設計により、組織や開発者は API Server の API プロファイルを変更して統合をカスタマイズしたり、独自の API プロファイルを作成したりすることも可能です。API Driver の接続性を あらゆる RESTful API に簡単に拡張できます。

この記事では、既存の API プロファイルを編集して、より多くの機能を有効にする方法を解説します。

API プロファイルの編集

デフォルトでは、既存の API プロファイルは API への読み取りアクセスを許可します。API プロファイルを編集することで、(サポートされている場合は)API への書き込みアクセスも取得できます。

既存のプロファイルを解凍する

API プロファイル(.apip ファイル)は、API で利用可能なエンドポイントを表すスキーマファイルのコレクションを含む圧縮フォルダです。ファイルを解凍すると、スキーマファイルを個別に編集して機能を拡張できます。

スキーマファイルを開く

プロファイルを解凍したら、変更したい API エンドポイントのスキーマファイルを(お好みのテキストエディタで)開きます。各スキーマファイルには、API エンドポイントへの SQL アクセスを有効にする方法を定義するいくつかの部分があります。

  • api:info: このキーワードは、スクリプト化されたカラム定義を通じて API フィールドをテーブルカラムにマッピングします。
  • attr: この要素はカラム定義を表します(詳細は後述)。
  • api:set attr="...": このキーワード(属性)は、ページング機能や API レスポンスの解析方法(RepeatElement 属性経由)などの情報を含む、API 統合のさまざまなパラメータを設定します。
  • api:script method="...": このキーワードは、API エンドポイントに対する読み取りおよび書き込み機能の実装方法を定義します。これには、呼び出される内部オペレーションや、フィルタリングなどの特定機能の管理方法が含まれます。

以下は、Zoom ミーティングを取得するためのスキーマファイルの完全な内容です。

Meetings.rsd


  
    <attr name="Id"         xs:type="string"   readonly="true" key="true"   other:xPath="id"         />
    <attr name="CreatedAt"  xs:type="datetime" readonly="true"              other:xPath="created_at" />
    <attr name="Duration"   xs:type="int"      readonly="true"              other:xPath="duration"   />
    <attr name="HostId"     xs:type="string"   readonly="true"              other:xPath="host_id"    />
    <attr name="JoinUrl"    xs:type="string"   readonly="true"              other:xPath="join_url"   />
    <attr name="StartTime"  xs:type="datetime" readonly="true"              other:xPath="start_time" />
    <attr name="Timezone"   xs:type="string"   readonly="true"              other:xPath="timezone"   />
    <attr name="Topic"      xs:type="string"   readonly="true"              other:xPath="topic"      />
    <attr name="Type"       xs:type="int"      readonly="true"              other:xPath="type" desc="1 - Instant. 2 - Scheduled. 3 - Recurring with no fixed time. 8 - Recurring with fixed time"      />
    <attr name="Uuid"       xs:type="string"   readonly="true"              other:xPath="uuid"       />
    <attr name="UserId"     xs:type="string"   desc="Required. Must be set to a user's Id or email address. All meetings retrieved will be for that user." other:pseudocolumn="true" />

    <input  name="MeetingType"     xs:type="string"   desc="Filters on meetings with the given type. Allowed values are scheduled, live, and upcoming. Default is live." values="live,scheduled,upcoming" default="active" other:filter="type" />
    <input  name="rows@next" desc="Identifier for the next page of results. Do not set this value manually." />
  

  
  <api:set attr="ContentType" value="application/json" />
  <api:set attr="RepeatElement" value="/" />
  <api:set attr="EnablePaging" value="true" />
  <api:set attr="RepeatElement" value="/meetings" />
  <api:set attr="pagenumberparam" value="page_number" />
  <api:set attr="pagesize" value="300" />
  <api:set attr="pagesizeparam" value="page_size" />
  <api:validate attr="_input.UserId" desc="You must specify a user Id when using the Meetings table." />
  <api:set attr="uri" value="https://api.zoom.us/v2/users/[_input.UserId | urlencode()]/meetings" />

  
    <api:set attr="method" value="GET" />
    
      <api:push/>
    
  


  
    <api:throw code="500" desc="Inserts are not supported." />
  
  
    <api:throw code="500" desc="Updates are not supported." />
  
  
    <api:throw code="500" desc="Deletes are not supported." />
  


カラム定義を更新する

書き込み機能を実装するには、適切なカラムに書き込み権限を許可するようにスキーマを変更する必要があります。プロファイルのカラム定義を更新する前に、単一のカラム定義を確認し、各種属性について説明します。

Id カラム定義

    <attr name="Id"         xs:type="string"   readonly="true" key="true"   other:xPath="id"         />

カラム定義の属性

  • name: API エンドポイントの SQL インターフェースにおけるカラム名
  • xs:type: カラムに関連付けられたデータ型(例: string、datetime、int など)
  • readonly: カラムが書き込みを許可するかどうか(デフォルトでは常に true)
  • key: カラムがテーブル / ビュー内の要素の一意識別子として意図されているかどうか
  • other:xPath: API レスポンス内のカラム値へのパス(RepeatElement からの完全または相対パス)

スキーマファイルから、ほとんどのカラム(さまざまな API フィールドに対応)が読み取り専用としてフラグ付けされていることがわかります。最初に行う編集は、読み取り専用フラグを削除して、API Driver が(API 仕様に基づいて)それらのカラムに書き込めるようにすることです:

...
    <attr name="Id"         xs:type="string"   readonly="true" key="true"   other:xPath="id"         />
    <attr name="CreatedAt"  xs:type="datetime" readonly="true"              other:xPath="created_at" />
    <attr name="Duration"   xs:type="int"                                   other:xPath="duration"   />
    <attr name="HostId"     xs:type="string"   readonly="true"              other:xPath="host_id"    />
    <attr name="JoinUrl"    xs:type="string"   readonly="true"              other:xPath="join_url"   />
    <attr name="StartTime"  xs:type="datetime"                              other:xPath="start_time" />
    <attr name="Timezone"   xs:type="string"                                other:xPath="timezone"   />
    <attr name="Topic"      xs:type="string"                                other:xPath="topic"      />
    <attr name="Type"       xs:type="int"                                   other:xPath="type" desc="1 - Instant. 2 - Scheduled. 3 - Recurring with no fixed time. 8 - Recurring with fixed time"      />
    <attr name="Uuid"       xs:type="string"   readonly="true"              other:xPath="uuid"       />
...

INSERT 機能を追加する

このセクションでは、以下のような INSERT ステートメントをサポートするようにスキーマファイルを変更する方法を解説します:

INSERT INTO Meetings
  (Topic,Type,StartTime,Duration,TimeZone,UserId)
VALUES
  ('Test Meeting',2,'2019-12-31T00:00:00',60,'EST','user@domain.com')

NOTE: Topic、Type、StartTime、Duration、TimeZone はすべてスキーマ内のカラムです。UserId attr は疑似カラムであり、テーブルカラムのように動作しますが、実際にはテーブルに格納されません。この場合、UserId は新しいミーティングを特定のユーザーアカウントに POST するために使用されます。

スキーマファイルでは、SELECT 機能は <api:script method="POST"> 要素内に実装されています:

  
    <api:set attr="method" value="GET" />
    
      <api:push/>
    
  

INSERT 機能を実装するには、<api:script method="POST"> 要素を変更し、method 属性の value を "POST" に設定し、入力値を data 属性に設定して、適切なオペレーション(この場合は apisadoExecuteJSONGet)を呼び出す必要があります。

method 属性の設定

  
    <api:set attr="method" value="POST" />
    
  

data 属性の設定

Zoom ミーティング API エンドポイントでは、新しいミーティングのさまざまなフィールドを含む JSON オブジェクトを送信することで、新しいミーティングを作成できます。INSERT ステートメントの値は _input オブジェクト内の対応するフィールドにマッピングされ、Zoom API に POST される data 属性の作成に使用されます。


{
  "topic": "[_input.Topic]",
  "type": [_input.Type],
  "start_time": "[_input.StartTime]",
  "duration": "[_input.Duration]",
  "timezone": "[_input.TimeZone]"
}

apisadoExecuteJSONGet オペレーションの呼び出し

data 属性が設定されたら、api:call キーワードを使用して apisadoExecuteJSONGet オペレーションを呼び出し、api:push キーワードでオペレーションを API Driver にプッシュします。


...
  
    
  

編集したプロファイルを使用する

スキーマファイルへの編集が完了したら、Zoom アカウントへのミーティングの INSERT を開始する準備ができました。スキーマファイルを保存し、スキーマファイルを再圧縮(zip)して、圧縮ファイルの拡張子を .apip に変更します。標準接続をサポートするアプリケーションを使用して、API Driver を介して API プロファイルに接続し、INSERT ステートメントを実行してください。

INSERT ステートメント

INSERT INTO Meetings
  (Topic,Type,StartTime,Duration,TimeZone,UserId)
VALUES
  ('Test Meeting (Edited Profile)',2,'2019-12-31T00:00:00',60,'EST','user@domain.com')

Zoom 上のミーティング

詳細情報と無料トライアル

これで、API Driver プロファイルに書き込み機能を追加できました。API Driver の詳細については、API Driver ページをご覧いただくか、対応する Knowledge Base の記事で API Driver のセットアップや新しいプロファイルの作成について詳しくお読みください(API Driver のセットアップ および API Driver プロファイルの作成)。API Driver をダウンロードして、RESTful API からのライブデータをコードを書かずにすぐに使い始めましょう。

始める準備はできましたか?

CData API Driver の詳細、または無料トライアルをダウンロード:

今すぐダウンロード