https://pact.io logo
#general
Title
# general
r

ritika arora

05/23/2022, 3:03 AM
Hi Team I need to configure webhook on provider in gitlab. Gitlab supports data only in form of form variables. How can I configure webhook to send form data? I tried following
Copy code
curl --location --request POST '<https://pact-broker.rcue102.viatorsystems.com/webhooks/consumer/event-service>' \
--header 'Content-Type: application/json' \
--data-raw '{
 "consumer": {
    "name": "event-service"
  },
  "provider": {
    "name": "product-service"
  },
  "request": {
    "method": "POST",
    "url": "<https://gitlab.dev.tripadvisor.com/api/v4/projects/{id}/trigger/pipeline>",
    "headers": {
      "Accept": "multipart/form-data"
    },
    "body": {
      "token": "TOKEN",
      "ref": "develop",
      "PIPELINE_LIBRARIES": "contract_verification,no_common",
      "PACT_CONSUMER_TAG": "${pactbroker.consumerVersionTags}"
    }
  },
  "events": [
    {
      "name": "contract_content_changed"
    }
  ]
}
'
curl i need to call is:
Copy code
curl --request POST \
  --form token=TOKEN \
  --form ref=develop \
  --form "variables[PIPELINE_LIBRARIES]=contract_verification,no_common" \
  "<https://gitlab.dev.tripadvisor.com/api/v4/projects/${PROJECT_ID}/trigger/pipeline>"
m

Matt (pactflow.io / pact-js / pact-go)

05/23/2022, 3:07 AM
Multipart values presumably would go in the body as key/value pairs
i.e. it’s not JSON
r

ritika arora

05/23/2022, 3:08 AM
yes so above curl should be correct?
🤷‍♂️ 1
but gitlab is not receiving form data
m

Matt (pactflow.io / pact-js / pact-go)

05/23/2022, 3:11 AM
from the curl or the webhook?
r

ritika arora

05/23/2022, 3:12 AM
from the webhook
m

Matt (pactflow.io / pact-js / pact-go)

05/23/2022, 3:12 AM
right
the webhook is posting JSON, not form values
r

ritika arora

05/23/2022, 3:14 AM
do you have any example how i can pass key value pairs?
i thought i sent key value pair in body
can you format this request, how you think it might work
Copy code
"request": {
    "method": "POST",
    "url": "<https://gitlab.dev.tripadvisor.com/api/v4/projects/{id}/trigger/pipeline>",
    "headers": {
      "Accept": "multipart/form-data"
    },
    "body": {
      "token": "TOKEN",
      "ref": "develop",
      "PIPELINE_LIBRARIES": "contract_verification,no_common",
      "PACT_CONSUMER_TAG": "${pactbroker.consumerVersionTags}"
    }
  },
m

Matt (pactflow.io / pact-js / pact-go)

05/23/2022, 3:17 AM
that’s json
body: “key=value&key2=val2…”
I’ll leave it with you to experiment from there.
r

ritika arora

05/23/2022, 3:18 AM
i tried it as above thinking it might work as query param
it did not work either
let me paste curl i tried
Copy code
curl --location --request POST '<https://pact-broker.rcue102.viatorsystems.com/webhooks/consumer/event-service>' \
--header 'Content-Type: application/json' \
--data-raw '{
 "consumer": {
    "name": "event-service"
  },
  "provider": {
    "name": "product-service"
  },
  "request": {
    "method": "POST",
    "url": "<https://gitlab.dev.tripadvisor.com/api/v4/projects/p1/trigger/pipeline?token=TOKEN&ref=develop&PACT_CONSUMER_TAG=${pactbroker.consumerVersionTags}&PIPELINE_LIBRARIES=contract_verification,no_common>",
    "headers": {
      "Accept": "multipart/form-data"
    }
  },
  "events": [
    {
      "name": "contract_content_changed"
    }
  ]
}
'
is the above request similar to what you thought?
m

Matt (pactflow.io / pact-js / pact-go)

05/23/2022, 3:23 AM
no, the key value pairs need to be on the
body
👀 1
it might be worth you googling how multipart forms are sent over HTTP. I think it will help you construct the webhook
r

ritika arora

05/23/2022, 3:23 AM
checking
i did check before asking, most of them are suggesting curl, or sending as data but will try to check more
m

Matt (pactflow.io / pact-js / pact-go)

05/23/2022, 3:26 AM
sure but curl is a specific tool, the broker doesn’t use curl to send these requests
4 Views