I am struggling to make a post request via CURL in my gitlabci file. I am attempting to post to an API, however, the body does not seem to be sent for some reason.
I have tested my curl request in various online validators as well as importing in postman, this all seems to work correctly.
The request authenticates correctly through our API, the body (-d) is simply not sent Is anyone able to point me in the right direction?
update:
stage: update
script:
- >-
curl -X POST -v --location "www.example.com/example" \
-H "Authorization: Api-Token anAPiToken" \
-H "Content-Type: application/json; charset=utf-8" \
-d '{ "entitySelector": "entityId(SERVICE-8E3722AC3F76B09D)",
"eventType": "CUSTOM_DEPLOYMENT",
"title": "New Deployment Triggered",
"properties": {
"RemediationUrl": "www.example.com/example"
}
}'
Sending -d in a single line Various different ways of using Curl within the gitlabci based on suggestions on other SO questions
I tested this in GitHub actions, but the principle should be the same for GitLab.
Currently your script evaluates to this:
Notice the extra
\characters in between. I assume you tried to add intentional line continuation on those lines, and not on the last JSON body part. However, that's not how it works.>-basically breaks down to two components:>strips all interior line breaks except the last one-is a chomping indicator "Stripping is specified by the “-” chomping indicator. In this case, the final line break and any trailing empty lines are excluded from the scalar’s content. "So in other words, you don't need to specify the line continuations by yourself with
\, those are already automatically stripped.So basically, this should work:
However, note that this will output everything on a single line. If you for some reason need and want the linebreaks on the POST body content, see How do I break a string in YAML over multiple lines? for more information.