Skip to content

Data loader WebAPI / save record

This document has been machine translated.

Save the record data based on the json obtained by loaderwebapi.init_record.

Endpoint

https://pf.xdata.nict.jp/api/v1/dataloaderapi/jsonrpc

Limitations

The amount of data that can be sent with one request is up to 100MB. Adjust so that the request body when sending is less than 100MB.

Request example 1

The following is an example request when data_name is defined with the name test_event_1 using loaderwebapi.register_loader.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "loaderwebapi.add_record",
  "params": {
    "data_name": "test_event_001",
    "options": {"if_exists": "override"},
    "record_set": [
       {
        "type": "Feature",
        "geometry": {"type": "Point", "coordinates": [130, 31]},
        "properties": {
          "start_datetime": "2021-01-01 00:00:00+09",
          "end_datetime": "2021-01-01 01:00:00+09",
          "test_varchar_1": "testvalue_1"
        }
      },
      {
        "type": "Feature",
        "geometry": {"type": "Point", "coordinates": [130, 31]},
        "properties": {
          "start_datetime": "2021-01-01 01:00:00+09",
          "end_datetime": "2021-01-01 02:00:00+09",
          "test_varchar_1": "testvalue_2"
        },
      }
    ]
  }
}

Response example 1

The following is the return contents in the above request example.

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "count": 2,
    "count_duplicate": 0,
    "count_insert": 2,
    "count_update": 0,
    "count_upload": 2,
    "message": "Of the 2 records uploaded, 0 were overwritten and 2 were inserted."
  }
}

Request Example 2

The following is a request to define data_name as test_event_1 using loaderwebapi.register_loader and save the file.

In the file attribute defined in loaderwebapi.register_loader, the value specified below must be specified as a key directly under record_def.

  • file_name_column
    • In the sample, file_name is used.
  • file_type_column
    • In the sample, file_type.
  • file_prefixid_column
    • In the sample: file_prefixid.
  • file_pathid_column
    • file_pathid_column In the sample: file_pathid.
  • file_relativepath_property
    • file_prefixid_column In the sample, relative_path.

The key specified as the file attribute specifies the actual file content as a base64 string. In the sample, only the first few bytes are shown and omitted, but test_file_1 corresponds to this key.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "loaderwebapi.add_record",
  "params": {
    "data_name": "test_event_1",
    "options": {
      "if_exists": "override"
    },
    "record_set": [
      {
        "geometry": {
          "type": "Point",
          "coordinates": [
            130,
            31
          ]
        },
        "properties": {
          "start_datetime": "2021-01-01 00:00:01+09",
          "end_datetime": "2021-01-01 00:00:05+09",
          "relative_path": "test_event_1_directory",
          "file_prefixid": 1,
          "file_pathid": "test_event_1_path_id",
          "file_type": "image/png",
          "file_name": "myfile.png",
          "test_file_1": "iVBO...." ,
          "test_varchar_1": "foobar_varchar"
        },
        "type": "Feature"
      }
    ]
  }
}

Response Example 2

The following is the return content of Request Example 2.

{
  "id": 1,
  "jsonrpc": "2.0",
  "result": {
    "count": 2,
    "count_duplicate": 0,
    "count_insert": 1,
    "count_update": 0,
    "count_upload": 1,
    "message": "Of the 1 records uploaded, 0 were overwritten and 1 was inserted."
  }
}

Parameters

Among the JSON-RPC request contents, the ones that can be specified in params are displayed below.

  • data_name: string

    • A name that points to the table in which you want to insert the data. Use the one specified in [loaderwebapi.register_loader]
  • record_set: array

    • Pass the geometry and properties of each element of GeoJson features returned by init_record with their values set.
    • As long as the key set of properties matches the data structure of the insertion destination, it is not necessary to correspond to the execution of init_record.
    • For the values of the file, bytea, and raster type attributes, set the value of properties to a base64-encoded string.
    • The value of the date attribute is passed as a character string. The string format must comply with ISO8601.
  • options: An associative array that specifies the behavior when inserting data.

    • if_exists: Specify one of override, skip, error - Specifies the behavior when data that matches the attributes (combination of start_datetime, end_datetime, location, etc.) corresponding to the unique key has already been registered.
      • override: Overwrite update of duplicate lines
      • skip: Skip without registering duplicate lines
      • error: Discard all lines without registering

Return values

  • count: Number of uploaded lines
  • count_upload: Number of uploaded lines
  • count_duplicate: Number of duplicate rows with existing table
  • count_insert: Number of INSERT rows
  • count_update: Number of UPDATE rows
  • message: Processing result message