Reputation: 1
I am trying to upload transaction data from an etherscan API to a Notions database. Unfortunately I get a validation error and cannot seem to figure it out. I am quite new to Notion so any help or tips are very appreciated! Thanks. I am using the following 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.`)
}
This is the error.
(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.
I tried different configurations but nothing worked.
Upvotes: 0
Views: 405
Reputation: 34
It looks like you are trying to insert a string in the timeStamp
property of the page you are trying to create.
Try making this field a number :
"timeStamp": {"number": Number(txn.timeStamp) },
Upvotes: 0