WebSpence
WebSpence

Reputation: 164

How can I pass JSON data to a webhook Chainlink job?

I am trying to get the "Pipeline Input" to somehow be passed to an external adapter via the $(jobRun.requestBody) pipeline variable and then parsed by a jsonparse task and then sent via a fetch task. I am not sure what format the input should be in when running a webhook job on a Chainlink node. I keep getting this and other errors no matter what I try:

data: key requestBody (segment 1 in keypath jobRun.requestBody): keypath not found

This is what I am seeing on the Chainlink Admin UI: enter image description here

Here is the closest thing I have found in the documentation:
- https://docs.chain.link/chainlink-nodes/oracle-jobs/job-types/webhook

Here is the job definition if useful:

type = "webhook"
schemaVersion = 1
name = "account-balance-webhook"
forwardingAllowed = false
observationSource = """
parse_request  [type="jsonparse" path="data,address" data="$(jobRun.requestBody)"]
fetch        [type=bridge name="test" requestData="{\\"id\\": \\"0\\", \\"data\\": { \\"address\\": \\"$(parse_request)\\"}}"]
parse        [type=jsonparse path="data,free" data="$(fetch)"]

    parse_request -> fetch -> parse
"""

I am running Chainlink in a Docker container with this image: smartcontract/chainlink:1.11.0-root

Some background: I am working on developing an external adapter and want to be able to easily and quickly test.

Upvotes: 0

Views: 71

Answers (1)

Matt - Block-Farms.io
Matt - Block-Farms.io

Reputation: 594

We use the following webhook job to quickly verify there is no syntax errors, etc. with the bridge to an EA.

type            = "webhook"
schemaVersion   = 1
name = "[WH-username] cbor0-v0"
observationSource   = """
    fetch [type="bridge" name="bridge_name" requestData="{ \\"id\\": $(jobSpec.externalJobID), \\"input1\\": \\"value1\\" }"]
    parse [type=jsonparse path="data,results" data="$(fetch)"]

    fetch -> parse
"""

In general, its best to quickly test an EA directly through curl GET/POST. If the curl works, then a bridge will work as long as you named the bridge correctly in the job-spec.toml

Upvotes: 0

Related Questions