0

I'm trying to read information from an api using a chainlink node. However, I came across an error that I couldn't resolve.

jsonparseError: could not resolve path ["assets.0.id"] in {"assets":[{"id":47699248,"num_sales":0,"background_color":null,"image_url":"https://storage.opensea.io/files/190273b6d8a335c4428d58caed63e8ee.svg","image_preview_url":"https://storage.opensea.io/files/190273b6d8a335c4428d58caed63e8ee.svg","image_thumbnail_url":"https://storage.opensea.io/files/190273b6d8a335c4428d58caed63e8ee.svg","image_original_url":null,"animation_url":null,"animation_original_url":null,"name":"RoundRobin #0","description":"RoundRobin is a full on-chain Robin.","external_link":null,"asset_contract":{"address":"0x15e49d9b58d91b781c264d1b828de6e5fe3feab9","asset_contract_type":"non-fungible","created_date":"2022-03-09T09:04:44.891296","name":"RoundRobin","nft_version":"3.0","opensea_version":null,"owner":null,"schema_name":"ERC721","symbol":"Robin","total_supply":null,"description":null,"external_link":null,"image_url":null,"default_to_fiat":false,"dev_buyer_fee_basis_points":0,"dev_seller_fee_basis_points":0,"only_proxied_transfers":false,"opensea_buyer_fee_basis_points":0,"opensea_seller_fee_basis_points":250,"buyer_fee_basis_points":0,"seller_fee_basis_points":250,"payout_address":null},"permalink":"https://testnets.opensea.io/assets/0x15e49d9b58d91b781c264d1b828de6e5fe3feab9/0","collection":{"banner_image_url":null,"chat_url":null,"created_date":"2022-03-09T09:04:45.528117","default_to_fiat":false,"description":null,"dev_buyer_fee_basis_points":"0","dev_seller_fee_basis_points":"0","discord_url":null,"display_data":{"card_display_style":"contain","images":[]},"external_url":null,"featured":false,"featured_image_url":null,"hidden":false,"safelist_request_status":"not_requested","image_url":null,"is_subject_to_whitelist":false,"large_image_url":null,"medium_username":null,"name":"RoundRobin - EQt3xOiVtN","only_proxied_transfers":false,"opensea_buyer_fee_basis_points":"0","opensea_seller_fee_basis_points":"250","payout_address":null,"require_email":false,"short_description":null,"slug":"roundrobin-eqt3xoivtn","telegram_url":null,"twitter_username":null,"instagram_username":null,"wiki_url":null,"is_nsfw":false},"decimals":0,"token_metadata":"data:application/json;base64,eyJuYW1lIjogIlJvdW5kUm9iaW4gIzAiLCAiZGVzY3JpcHRpb24iOiAiUm91bmRSb2JpbiBpcyBhIGZ1bGwgb24tY2hhaW4gUm9iaW4uIiwgImltYWdlIjogImRhdGE6aW1hZ2Uvc3ZnK3htbDtiYXNlNjQsUEhOMlp5QjNhV1IwYUQwaU16QXdJaUJvWldsbmFIUTlJak13TUNJZ2RtbGxkMEp2ZUQwaU1Dd2dNQ3dnTXpBd0xDQXpNREFpSUhodGJHNXpQU0pvZEhSd09pOHZkM2QzTG5jekxtOXlaeTh5TURBd0wzTjJaeUkrUEhKbFkzUWdkMmxrZEdnOUlqRXdNQ1VpSUdobGFXZG9kRDBpTVRBd0pTSWdabWxzYkQwaUkyWXlaV1ZqWWlJZ0x6NDhabTl5WldsbmJrOWlhbVZqZENCNFBTSXhNQ0lnZVQwaU1UQWlJSGRwWkhSb1BTSXlPREFpSUdobGFXZG9kRDBpTWpnd0lqNDhaR2wySUhodGJHNXpQU0pvZEhSd09pOHZkM2QzTG5jekxtOXlaeTh4T1RrNUwzaG9kRzFzSWlCemRIbHNaVDBpWm05dWRDMXphWHBsT25ndGMyMWhiR3c3ZEdWNGRDMXBibVJsYm5RNk1XVnRJajQ4Y0Q1MmFYUmhiR2xyUEM5d1BqeHdQblJ2Y21Fak1Ed3ZjRDQ4TDJScGRqNDhMMlp2Y21WcFoyNVBZbXBsWTNRK1BDOXpkbWMrIn0=","is_nsfw":false,"owner":{"user":{"username":"tomoking"},"profile_img_url":"https://storage.googleapis.com/opensea-static/opensea-profile/19.png","address":"0x16ea840cfa174fdac738905c4e5db59fd86912a1","config":""},"sell_orders":null,"creator":null,"traits":[],"last_sale":null,"top_bid":null,"listing_date":null,"is_presale":false,"transfer_fee_payment_token":null,"transfer_fee":null,"token_id":"0"}]}: keypath not found

code is here

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;

import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

contract APIConsumer is ChainlinkClient {
    using Chainlink for Chainlink.Request;
  
    uint256 public volume;
    
    address private oracle;
    bytes32 private jobId;
    uint256 private fee;

    constructor() {
        setPublicChainlinkToken();
        oracle = 0xD8269ebfE7fCdfCF6FaB16Bb4A782dC8Ab59b53C;
        jobId = "2e0441fe857e45bca8f0d349bb680afd";
        fee = 0.1 * 10 ** 18; 
    }
    
    function requestVolumeData() public returns (bytes32 requestId) 
    {
        Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfill.selector);
        
        request.add("get", "https://testnets-api.opensea.io/api/v1/assets?owner=0x16ea840cfA174FdAC738905C4E5dB59Fd86912a1&order_direction=desc&offset=0&limit=1");

        request.add("path", "assets");
        
        int timesAmount = 10**18;
        request.addInt("times", timesAmount);

        return sendChainlinkRequestTo(oracle, request, fee);
    }

    function fulfill(bytes32 _requestId, uint256 _volume) public recordChainlinkFulfillment(_requestId)
    {
        volume = _volume;
    }
}

And job code is here.

type = "directrequest"
schemaVersion = 1
name = "Get > Uint256"
externalJobID = "2e0441fe-857e-45bc-a8f0-d349bb680afd"
maxTaskDuration = "0s"
contractAddress = "0xD8269ebfE7fCdfCF6FaB16Bb4A782dC8Ab59b53C"
minIncomingConfirmations = 0
observationSource = """
    decode_log   [type="ethabidecodelog"
                  abi="OracleRequest(bytes32 indexed specId, address requester, bytes32 requestId, uint256 payment, address callbackAddr, bytes4 callbackFunctionId, uint256 cancelExpiration, uint256 dataVersion, bytes data)"
                  data="$(jobRun.logData)"
                  topics="$(jobRun.logTopics)"]

    decode_cbor  [type="cborparse" data="$(decode_log.data)"]
    fetch        [type="http" method=GET url="$(decode_cbor.get)"]
    parse        [type="jsonparse" path="$(decode_cbor.path)" data="$(fetch)"]
    multiply     [type="multiply" input="$(parse)" times=100]
    encode_data  [type="ethabiencode" abi="(uint256 value)" data="{ \\"value\\": $(multiply) }"]
    encode_tx    [type="ethabiencode"
                  abi="fulfillOracleRequest(bytes32 requestId, uint256 payment, address callbackAddress, bytes4 callbackFunctionId, uint256 expiration, bytes32 data)"
                  data="{\\"requestId\\": $(decode_log.requestId), \\"payment\\": $(decode_log.payment), \\"callbackAddress\\": $(decode_log.callbackAddr), \\"callbackFunctionId\\": $(decode_log.callbackFunctionId), \\"expiration\\": $(decode_log.cancelExpiration), \\"data\\": $(encode_data)}"
                 ]
    submit_tx    [type="ethtx" to="0xD8269ebfE7fCdfCF6FaB16Bb4A782dC8Ab59b53C" data="$(encode_tx)"]

    decode_log -> decode_cbor -> fetch -> parse -> multiply -> encode_data -> encode_tx -> submit_tx
"""

I learned to use A.0.B instead of A [0] .B for errors that occur in arrays, but it wasn't my solution. .. ..

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.