Chainlink request not returning the integer at the followed path

Viewed 126

I have a very simple smart contract which creates and sends a Chainlink request to the Kovan Linkpool node using the get>uint256 job. The contract looks like this (API private key removed).

contract OracleChainlink is ChainlinkClient {
    using Chainlink for Chainlink.Request;

    uint256 public H_Index;
    address private Oracle;
    bytes32 private JobId;
    uint256 private Fee = .1 * 10 ** 18; //kovan is .1 link per call

    constructor() public {
        setPublicChainlinkToken();
        Oracle = 0x56dd6586DB0D08c6Ce7B2f2805af28616E082455; //Chainlink linkpool node on Kovan
        JobId = "b6602d14e4734c49a5e1ce19d45a4632";
    }

    function getChainlinkToken() public view returns (address) {
        return chainlinkTokenAddress();
    }

    function RequestH_index() public returns (bytes32 Reqid) {
        Chainlink.Request memory Req = buildChainlinkRequest(JobId, address(this), this.fulfill.selector);

        Req.add("get", "https://serpapi.com/.....");
        Req.add("path", "cited_by.table.1.h_index.all");

        return sendChainlinkRequestTo(Oracle, Req, Fee);        
    }
    
    function fulfill(bytes32 Reqid, uint256 _Hindex) public recordChainlinkFulfillment(Reqid) {
        H_Index = _Hindex;
    }

The Google Scholar Author API https://serpapi.com/google-scholar-author-api returns a pretty large json, seen at the link if you scroll down. The snippet/path I need to follow is shown below (cited_by is at the top level of the json).

  "cited_by": {
    "table": [
      {
        "citations": {
          "all": 23351,
          "since_2016": 13660
        }
      },
      {
        "h_index": {
          "all": 46,
          "since_2016": 37
        }
      },
      {
        "i10_index": {
          "all": 60,
          "since_2016": 53
        }
      }
    ],

When ran, I get logs of Chainlink request events, but the public H_Index value remains 0. Am I missing something in terms of adapters? I have tried all sorts of path formats through the JSON with no luck. I have also tried different nodes and jobs. Is there any way to ensure that the API is even being called? What am I missing?

1 Answers

Your JSON Path should look like this:

Req.add("path", "cited_by.table.1.h_index.all");

Looking at the Etherscan activity, it looks like the node you are using may be inactive. Try this node and jobId:

Oracle = 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8; 
JobId = "d5270d1c311941d0b08bead21fea7747";

These were taken from the Chainlink Official Docs.

To check to see if a node is running or not, check out the oracle address in a block explorer. You can see here that the original node you tried to use hasn't posted a transaction in quite a long time.

If a node is inactive you will need to find a new one or host one yourself. To find more nodes and jobs, you can check market.link or use the one found in the docs as mentioned earlier.

Related