I’m trying to get data from an off-chain API to use it in my smart contract. For this, I’m using Chainlink oracle.
I can get data from api like this:
[{“id”:1,”name”:”John Smith”,”email”:”[email protected]”,”values”:[8.03,0.8,1.49,5.71,3.44,7.1,5.74],”quantities”:[1,2,20,11,19,10,20]},
{“id”:2,”name”:”Emily Johnson”,”email”:”[email protected]”,”values”:[1.11,3.62,9.15,6.15,1.5,2.91,9.3],”quantities”:[13,20,17,14,20,10,3]},
{“id”:3,”name”:”Michael Brown”,”email”:”[email protected]”,”values”:[2.71,9.16,8.44,4.25,7.59,8.15,0.26],”quantities”:[11,6,4,19,2,14,20]}]
To get an array from api, I did like that:
constructor() ConfirmedOwner(msg.sender) {
_setChainlinkToken(0x779877A7B0D9E8603169DdbD7836e478b4624789);
_setChainlinkOracle(0x6090149792dAAeE9D1D568c9f9a6F6B46AA29eFD);
jobId = "53f9755920cd451a8fe46f5087468395";
fee = (1 * LINK_DIVISIBILITY) / 10; // 0,1 * 10**18 (Varies by network and job)
}
function requestFirstId() public returns (bytes32 requestId) {
Chainlink.Request memory req = _buildChainlinkRequest(
jobId,
address(this),
this.fulfill.selector
);
req._add(
"get",
url
);
req._add("path", "0,values,0");
req._add("path", "0,values,1");
int256 timesAmount = 10 ** 18;
req._addInt("times", timesAmount);
return _sendChainlinkRequest(req, fee);
}
function fulfill(
bytes32 _requestId,
uint256 _value0,
uint256 _value1
) public recordChainlinkFulfillment(_requestId) {
emit RequestFirstId(_requestId, _value0);
value0 = _value0;
value1 = _value1;
}
But it isn’t worked.
And I want to get values and quantities from this api
How can I get the values and quantities using Chainlink Oracle?