> ## Documentation Index
> Fetch the complete documentation index at: https://www.integrate.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# ETL: Curl Functionを使ったデータ更新

> Integrate.io ETLのCurl関数を使い、外部クラウドアプリケーションのAPIを呼び出して変換後のデータを保存先へ自動更新する連携方法を紹介します。

## シナリオ説明

今回のテーマは「多様なデータ連携」に関するトピックです。昨今クラウド時代の到来により、データの抽出方法や保存先へのデータ更新方法は非常に多様になりました。クラウドアプリケーションのほとんどがAPIによるデータ抽出や更新方法をサポートしていたりします。

今回は、APIを利用したデータ更新について紹介してみたいと思います。

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-1.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=4d051442ad7d48df0044a6075ba82f91" alt="restapi-part06-jp image 1" width="1230" height="522" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-1.webp" />
</Frame>

ETLツールがAPIの仕様に合わせて相手先アプリケーションにデータ書き込むことができるってご存知だったでしょうか？昨今のETLでは、それが可能な製品もいくつか出てきているのですが、意外と知らない方も多いのではないかと思います。

では、どうやってXplentyでは実現できるのでしょうか？
まず今回作るパッケージ（データ取得から更新までの一連の処理）の概要を紹介します。

早速、言い訳になりますが、この処理自体は、ビジネス的には全く意味がないデータ連携処理です。
ここでは、どのようにソースシステムからデータが連携され、データ保管先に書き込まれるかの流れを見ていただければと思います。

## パッケージ作成

**1.データ取得処理**

まずNHKのAPIに対してデータを取得するための設定です。
XplentyのSourceのリストにある「Rest API」コンポーネントを使用します。

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-2.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=87c863c259f710c3d9fa363b590e236b" alt="restapi-part06-jp image 2" width="1146" height="884" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-2.webp" />
</Frame>

コンポーネントで以下のようにURLを設定していきます。

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-3.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=65020248f5efe842771835b168f544e9" alt="restapi-part06-jp image 3" width="1146" height="884" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-3.webp" />
</Frame>

さらに取得する項目「title(番組名)」と「subtitle(番組サブタイトル)」をセットします。

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-4.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=417962b55c6706e8c51b8778d875ec1d" alt="restapi-part06-jp image 4" width="1220" height="884" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-4.webp" />
</Frame>

これでデータ取得側の設定は完了です。

**2.データ更新処理**

次はデータ更新処理を設定します。

Transformationで「Select」コンポーネントを選択します。

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-5.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=b150f9a14d883915ff8616546cd456c7" alt="restapi-part06-jp image 5" width="1220" height="884" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-5.webp" />
</Frame>

Selectコンポーネントの式エディタを開き、Trello側のAPIの仕様に合わせて、以下の式をセットします。

コマンドとしては以下のようになります。
`Curl(CONCAT('https://trello.com/1/cards?key=$mykey&token=$mytoken&idList=xxxxxxxxx&name=',URLEncode(title),'&desc=',URLEncode(subtitle)),'POST','&#123;"Accept":"text/json"&#125;')`

さらにCurlコマンドの結果のうち、 Status部分を取得し、ログとして出力できるように上記の式にプラスで赤字部分を設定しています。

`Curl(CONCAT('https://trello.com/1/cards?key=$mykey&token=$mytoken&idList=xxxxxxxxx&name=',URLEncode(title),'&desc=',URLEncode(subtitle)),'POST','&#123;"Accept":"text/json"&#125;')#'status'`

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-6.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=d35e2a5df70736e8d5353a5f4018c51a" alt="restapi-part06-jp image 6" width="1220" height="884" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-6.webp" />
</Frame>

リクエスト結果（statusのみ取得）をセットする列の名称をALIASにセットします。

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-7.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=ac5e05da9824dc680128b9fbf5b1979e" alt="restapi-part06-jp image 7" width="1536" height="548" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-7.webp" />
</Frame>

あとは結果をストレージなど、Destinationにある任意のコンポーネントを選択し、Curlの結果ログ（今回は「Status」のみ）を保存するだけです。

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-8.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=0c61cfa6b61549db8e6f693edf17d821" alt="restapi-part06-jp image 8" width="1320" height="884" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-8.webp" />
</Frame>

最終的なパッケージは以下のようになります。

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-9.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=f9b0b9557b0baacf4e432d9572c87e5c" alt="restapi-part06-jp image 9" width="1980" height="1174" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-9.webp" />
</Frame>

**3.結果を確認**

実際にデータを実行してみましょう。

狙い通り、指定したリストに連携したデータに基づいて作成されたカードががセットされていることを確認できます。

<Frame>
  <img src="https://mintcdn.com/integrateio/u3KZjgbItgbZsh3u/images/japanese-knowledge-base/restapi-part06-jp/image-10.webp?fit=max&auto=format&n=u3KZjgbItgbZsh3u&q=85&s=8275c744cae71aaa821c87d7260d5452" alt="restapi-part06-jp image 10" width="1868" height="618" data-path="images/japanese-knowledge-base/restapi-part06-jp/image-10.webp" />
</Frame>

## 最後に

今回はRest APIで取得したデータをRest APIを使って更新してみました。

[Xplenty](https://www.xplenty.com/jp/)はG2 Crowdにて2020年SpringのETLツールカテゴリにおいて「Leader」に選ばれています。（G2 Crowdのレビューページでは、ユーザーの声がビデオで紹介されており、変換の多様性、すぐに使えるコネクタの豊富さ、サポートのレスポンスの良さ、学習が容易といった点を評価していただいてます。）

是非、この機会にクラウドETL「Xplenty」を[1ヶ月間無償トライアル](https://try.xplenty.com/jp/)で体験してみてください。
