> ## 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: HubspotのデータをAPIで更新する

> S3に保管されたコンタクトリストのCSVファイルをXplentyのCurlファンクションとHubspot APIを使用して読み込み、HubspotのContactデータを更新する方法を画面キャプチャとともに解説します。

前回は[Xplenty: HubspotのデータをAPIで取得する](/jp/etl/restapi-part03-jp)方法について紹介しましたが、今回はHubspotのAPIを使用し、XplentyからHubspotのContactデータを更新する方法について解説します。

**今回使用するAPIに関する参考ドキュメント：**\
[https://legacydocs.hubspot.com/docs/methods/contacts/create\_or\_update](https://legacydocs.hubspot.com/docs/methods/contacts/create_or_update)

## データの書き込み

今回の例では、S3に保管されているコンタクトリストのCSVファイルをHubspotに更新する方法について紹介します。

## ストレージコンポーネント（ソース）を使用して、S3から今回Hubspotに更新するデータを取得します

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

## SelectコンポーネントでCurlファンクションを使用してリクエストを定義します

**Select コンポーネントの設定画面**

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

**リクエスト例：**`https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/メールアドレスの列名/?hapikey=APIキー`

**リクエストBody例：**

```
{ "properties": [ { "property": "firstname", "value": "firstnameの列名" }, { "property": "lastname", "value": "lastnameの列名" }, { "property": "company", "value": "企業名の列名" } ] }
```

**上記を参考にXplentyでのCurlファンクションを使用し、関数式にする**

```
Curl(CONCAT('https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/',mail,'/?hapikey=APIキー'),'POST','{"content-type":"application/json"}', CONCAT( '{ "properties": [{"property": "firstname","value": "',FirstName ,'" }, {"property": "lastname","value": "' ,LastName,'" },{"property": "company","value": "',Company,'" }]}' ))#'status'
```

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

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

## Xplentyでジョブ実行結果を確認する

ジョブが正しく実行され、各メールアドレスに対するリクエストが成功（ステータス:200）していることが分かります。

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

実際のHubspot側の画面で確認すると、ジョブ実行前の画面に対して、正しく追加、更新されていることが確認できます。

**ジョブ実行前：**

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

**ジョブ実行後：**

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

**変数をうまく利用する**

今回は分かりやすいようにAPI KeyやURLについて固定値でセットする方法で紹介しましたが、変数を利用することで
