購買履歴アップロードAPI

購買履歴アップロードAPI について

APIの他、バッチ処理によるアップロード機能もご利用いただけます。
詳細は営業担当・もしくはサポートまでお問い合わせください。

概要

利用方法

  • 1日単位の購買履歴をアップロードします
  • アップロードしたデータは、翌日早朝に取り込まれます
  • 同じ日のデータを複数回アップロードした場合、当日受け付けた最後のデータが取り込まれます

※変更、削除のAPIは現状提供しておりません

利用例

  • 1日目、以下の購買履歴をAPIへリクエスト
    • 11/1 商品A購入
    • 11/1 商品B購入
    • 11/1 商品C購入
  • 2日目、購買履歴がFANSHIPへ取り込まれる
    • 11/1 商品A購入
    • 11/1 商品B購入
    • 11/1 商品C購入
  • 2日目、以下の購買履歴をAPIへリクエスト
    • 11/2 商品A購入
    • 11/2 商品B購入
    • 11/2 商品C購入
  • 3日目、購買履歴がFANSHIPへ取り込まれる
    • 11/1 商品A購入
    • 11/1 商品B購入
    • 11/1 商品C購入
    • 11/2 商品A購入
    • 11/2 商品B購入
    • 11/2 商品C購入

注意:最後に受け取ったAPIリクエストのみ取り込みます

不正なリクエスト

必須項目が指定されていなかったり、バリデーションに違反するリクエストが行われた場合、400 Bad Requestを返却します。
存在しないキーが指定されていた場合、該当のキーが無視されます。

注意: 不正なキーが存在していても、該当キーが無視され正常に処理されます

URL

  • https://${hostname}/v1/2nd/purchases/${yyyymmdd}/_all
    • yyyymmdd
      • 取り込むデータの営業日

Method

  • POST

ファイルアップロード形式

multipart/form-dataによりアップロードします

コンテンツタイプ

  • Content-Type: multipart/form-data; boundary=----${Boundary}

FormData

以下のフォーマットに沿ったFormDataを使用します

  • Content-Disposition: form-data; name="filename"; filename="blob"
  • Content-Type: application/x-ndjson

ファイル形式

  • 行区切りJSON(x-ndjson)

スキーマ

キー名 タイプ 必須 意味 備考
id STRING 必須 購買ID
transaction_id STRING - 決済ID
store_id STRING - 店舗ID
member_id STRING - 会員ID 会員情報のID
order_status STRING - 返品など
order_date TIMESTAMP - 受注日時
item_name STRING - 商品名
item_category STRING - 商品カテゴリ
item_code STRING - 商品コード
jan_code INTEGER - JANコード
fixed_price FLOAT - 定価 (円)
discounted_price FLOAT - 割引価格 (円)
market_price FLOAT - 実売価格 (円) 税抜き価格
discount_rate FLOAT - 割引率
shipping_price FLOAT - 送料 (円)
shipping_address STRING - 配送先
packaging_price INTEGER - 包装価格 (円)  
quantity INTEGER - 数量
paymethod STRING - 支払い方法
card_brand STRING - クレジットカードブランド
tax FLOAT - 税額 (円)
tax_rate FLOAT - 税率
promotion_id ARRAY[STRING] - プロモーションID
subscription BOOLEAN - 定期購入
property ARRAY[OBJECT] - 追加属性 [{"key": "key",
"value": "value"}]
property.key STRING - 追加属性(Key)
property.value STRING - 追加属性(Value)

JSONスキーマ

JSONスキーマを使用することで、行ごとにバリデーションを実施する事ができます。 ※Version: draft-07

{
    "type": "object",
    "properties": {
        "id": {
            "type": "string",
            "minLength": 1,
            "description": "購買ID",
            "examples": [
                "purchases_id"
            ]
        },
        "transaction_id": {
            "type": ["string", "null"],
            "items": {
                "type": "string"
            },
            "default": null,
            "description": "決済ID",
            "examples": [
                "123456789"
            ]
        },
        "store_id": {
            "type": ["string", "null"],
            "items": {
                "type": "string"
            },
            "default": null,
            "description": "店舗ID",
            "examples": [
                "store_a"
            ]
        },
        "member_id": {
            "type": ["string", "null"],
            "default": null,
            "description": "会員ID",
            "examples": [
                "member_id"
            ]
        },
        "order_status": {
            "type": ["string", "null"],
            "default": null,
            "description": "返品など",
            "examples": [
                "buy"
            ]
        },
        "order_date": {
          "type": ["string", "null"],
            "format": "date-time",
            "default": null,
            "description": "受注日時",
            "examples": [
                "2020-01-01T00:00:00+09:00"
            ]
        },
        "item_name": {
            "type": ["string", "null"],
            "default": null,
            "description": "商品名",
            "examples": [
                "item_a"
            ]
        },
        "item_category": {
            "type": ["string", "null"],
            "default": null,
            "description": "商品カテゴリ",
            "examples": [
                "food"
            ]
        },
        "item_code": {
            "type": ["string", "null"],
            "default": null,
            "description": "商品コード",
            "examples": [
                "123456789"
            ]
        },
        "jan_code": {
            "type": ["integer", "null"],
            "default": null,
            "description": "JANコード",
            "examples": [
                12345678
            ]
        },
        "fixed_price": {
            "type": ["number", "null"],
            "default": null,
            "description": "定価(円)",
            "examples": [
                100
            ]
        },
        "discounted_price": {
            "type": ["number", "null"],
            "default": null,
            "description": "割引価格(円)",
            "examples": [
                100
            ]
        },
        "market_price": {
            "type": ["number", "null"],
            "default": null,
            "description": "実売価格 税抜き価格(円)",
            "examples": [
                100
            ]
        },
        "discount_rate": {
            "type": ["number", "null"],
            "default": null,
            "description": "割引率",
            "examples": [
                1
            ]
        },
        "shipping_price": {
            "type": ["number", "null"],
            "default": null,
            "description": "送料(円)",
            "examples": [
                100
            ]
        },
        "shipping_address": {
            "type": ["string", "null"],
            "default": null,
            "description": "配送先",
            "examples": [
                "東京都港区麻布台1丁目11−9"
            ]
        },
        "packaging_price": {
            "type": ["number", "null"],
            "default": null,
            "description": "包装価格(円)",
            "examples": [
                100
            ]
        },
        "quantity": {
            "type": ["integer", "null"],
            "default": null,
            "description": "数量",
            "examples": [
                1
            ]
        },
        "paymethod": {
            "type": ["string", "null"],
            "default": null,
            "description": "支払い方法",
            "examples": [
                "card"
            ]
        },
        "card_brand": {
            "type": ["string", "null"],
            "default": null,
            "description": "クレジットカードブランド",
            "examples": [
                "jcb"
            ]
        },
        "tax": {
            "type": ["number", "null"],
            "default": null,
            "description": "税額(円)",
            "examples": [
                10
            ]
        },
        "tax_rate": {
            "type": ["number", "null"],
            "default": null,
            "description": "税率(%)",
            "examples": [
                10
            ]
        },
        "subscription": {
            "type": ["boolean", "null"],
            "default": null,
            "description": "定期購入",
            "examples": [
                false
            ]
        },
        "property": {
            "type": ["array", "null"],
            "items": {
                "type": "object",
                "properties": {
                    "key": {
                        "type": "string"
                    },
                    "value": {
                        "type": "string"
                    }
                }
            },
            "maxItems": 100,
            "description": "追加情報、key,valueで自由入力",
            "examples": [
                [{"key": "property_key", "value": "property_value"}]
            ]
        }
    },
    "required": ["id"]
}

※追加属性となる「property」は最大100個まで設定可能となります

リクエストサンプル

curlの実行

curl -X POST  -F 'filename=@purchases.json;type=application/x-ndjson' -H 'Authorization: Bearer ${AUTH_TOKEN}' 'https://${hostname}/v1/2nd/purchases/${yyyymmdd}/_all'

送信データ

POST /v1/2nd/purchases/${yyyymmdd}/_all HTTP/1.1
User-Agent: curl/7.35.0
Host: ${hostname}
Accept: */*
Authorization: Bearer ${AUTH_TOKEN}
Content-Length: 594
Expect: 100-continue
Content-Type: multipart/form-data; boundary=------------------------18eaed0d99a868ap

--------------------------18eaed0d99a868ap
Content-Disposition: form-data; name="filename"; filename="purchases.json"
Content-Type: application/x-ndjson

{"order_date":"2020-02-03T10:03:31+09:00","member_id":"10001000000000010157","id":"c5404d03-d3b6-4bc8-b2cf-305f516fb3c0","store_id":"483","fixed_price":100.0,"market_price":100.0,"order_status":""}
{"order_date":"2020-02-03T10:03:31+09:00","member_id":"10001000000000010157","id":"14c4765a-b331-43a6-b15c-09de1aa3e24f","store_id":"483","fixed_price":100.0,"market_price":100.0,"order_status":""}
{"order_date":"2020-02-03T10:03:31+09:00","member_id":"10001000000000010157","id":"9a3021de-ea57-4e0e-afb1-f0c3cdc6d66e","store_id":"483","fixed_price":100.0,"market_price":100.0,"order_status":""}

--------------------------18eaed0d99a868ap--