如何修复此 Notion API 验证错误?

问题描述 投票:0回答:1

我正在尝试将交易数据从 etherscan API 上传到 Notions 数据库。不幸的是我收到验证错误并且似乎无法弄清楚。我对 Notion 还很陌生,所以非常感谢任何帮助或提示!谢谢。 我正在使用以下 API: https://docs.etherscan.io/api-endpoints/accounts#get-a-list-of-internal-transactions-by-address

const axios = require("axios");
const { Client } = require("@notionhq/client");
const notion = new Client({
  auth: "xyz",
});
var api = require("etherscan-api").init("U8E3BPUHXC471WBUC3SBXC8H2W5KBNRU1F");
var balance = api.account.balance("0x699791A03Ac2B58E1B7cA29B601C69F223c78e9c");
const txnArray = []

async function getWallet() {
  for (let i = 0; i <= 9;i++){
    
  
  await axios
    .get( "https://api.etherscan.io/api?module=account&action=txlistinternal&address=0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3&startblock=0&endblock=2702578&page=1&offset=10&sort=asc&apikey=U8E3BPUHXC471WBUC3SBXC8H2W5KBNRU1F"
    )
    .then((wallet) => {
    const walletData = {
      "blockNumber": wallet.data.result[i].blockNumber,
      "timeStamp": wallet.data.result[i].timeStamp,
      "hash": wallet.data.result[i].hash,
      "from": wallet.data.result[i].from,
      "to": wallet.data.result[i].to,
      "value": wallet.data.result[i].value,
      "contractAddress": wallet.data.result[i].contractAddress,
      "input": wallet.data.result[i].input,
      "type": wallet.data.result[i].type,
      "gas": wallet.data.result[i].gas,
      "gasUsed": wallet.data.result[i].gasUsed,
      "traceId": wallet.data.result[i].traceId,
      "isError": wallet.data.result[i].isError,
      "errCode": wallet.data.result[i].errCode,
    }
    txnArray.push(walletData)
    console.log("value "+ walletData.value)
    console.table(walletData)
    //console.log(wallet.data.result[i].blockNumber);
    //console.log(wallet)//shows whole api output
      ;
    })
    .catch((error) => {
      console.log(error);
    });
  }  
  createNotionPage()
}

getWallet();

async function createNotionPage() {
  
  for (const txn of txnArray) {
    
    const data = {
      "parent": {
        "type": "database_id",
        "database_id": "6589a15bde06491b9c9b9bfac52ba782",
      }, 
      "properties": {
        "blockNumber": {
          "title": [
            {
              "text": {
                "content": txn.blockNumber
              }
            }
          ]
        },
        "timeStamp": {"number": txn.timeStamp},
        "hash": { "text": txn.hash },
        "from": { "text": txn.from },
        "to": { "text": txn.to },
        "value": { "number": txn.value },
        "contractAddress": { "text": txn.contractAddress },
        "input": { "text": txn.input },
        "type": { "text": txn.type },
        "gas": { "number": txn.gas },
        "gasUsed": { "number": txn.gasUsed },
        "traceId": { "number": txn.traceId },
        "isError": { "number": txn.isError },
        "errCode": { "number": txn.errCode }
      }
    }
    console.log(txn.timeStamp)
    console.log(`Sending ${txn.hash} to Notion`)
    const response = await notion.pages.create( data )
    console.log(response)
    
    
  }
  
  console.log(`Operation complete.`)
  
}

这是错误。

(node:24027) UnhandledPromiseRejectionWarning: APIResponseError: body failed validation. Fix one:
body.properties.timeStamp.title should be defined, instead was `undefined`.
body.properties.timeStamp.rich_text should be defined, instead was `undefined`.
body.properties.timeStamp.number should be a number or `null`, instead was `"1477837690"`.
body.properties.timeStamp.url should be defined, instead was `undefined`.
body.properties.timeStamp.select should be defined, instead was `undefined`.
body.properties.timeStamp.multi_select should be defined, instead was `undefined`.
body.properties.timeStamp.people should be defined, instead was `undefined`.
body.properties.timeStamp.email should be defined, instead was `undefined`.
body.properties.timeStamp.phone_number should be defined, instead was `undefined`.
body.properties.timeStamp.date should be defined, instead was `undefined`.
body.properties.timeStamp.checkbox should be defined, instead was `undefined`.
body.properties.timeStamp.relation should be defined, instead was `undefined`.
body.properties.timeStamp.files should be defined, instead was `undefined`.
body.properties.timeStamp.status should be defined, instead was `undefined`.
body.properties.blockNumber.id should be defined, instead was `undefined`.
body.properties.blockNumber.name should be defined, instead was `undefined`.
body.properties.blockNumber.start should be defined, instead was `undefined`.
    at buildRequestError (/rbd/pnpm-volume/ab2d2251-8f87-4abc-9064-f7f0b68836e4/node_modules/@notionhq/client/build/src/errors.js:162:16)
    at Client.request (/rbd/pnpm-volume/ab2d2251-8f87-4abc-9064-f7f0b68836e4/node_modules/@notionhq/client/build/src/Client.js:378:54)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async createNotionPage (/app/index.js:86:22)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:24027) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:24027) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

我尝试了不同的配置,但没有任何效果。

javascript error-handling notion-api notion notion-js
1个回答
0
投票

您似乎正在尝试在您尝试创建的页面的

timeStamp
属性中插入一个字符串。

尝试将此字段设置为数字:

"timeStamp": {"number": Number(txn.timeStamp) },
© www.soinside.com 2019 - 2024. All rights reserved.