Issue
Trying to create a Context in CircleCI via API. Reference document: https://circleci.com/docs/api/v2/#tag/Context
I have created a personal api token and encoded into base64 as per requirement, to use in basic auth command.
I am using curl command like below:
name: "Create Context"
command:
curl --request POST \
--url https://circleci.com/api/v2/context \
--header 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxx' \
--header 'content-type:' 'application/json' \
--data '{"name":"string","owner":{"id":"string","type":"organization"}}'
I am getting error like below:
Unable to parse YAML
mapping values are not allowed here
in 'string', line 23, column 36:
--header 'authorization: xxxxxxxxxxxxxxx ...
I tried having double quotes around for escape character in that line but still same error. can you please suggest right way
Solution
The multiline string value syntax in YAML is different. There is no backslash-escapes-newline logic there. It should go:
name: "Create Context"
command: >
curl --request POST
--url https://circleci.com/api/v2/context
--header 'authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxx'
--header 'content-type:' 'application/json'
--data '{"name":"string","owner":{"id":"string","type":"organization"}}'
The end of the string is indicated by indentation, as YAML does.
Note that YAML parsing is not being done by CURL itself. You have a curl
command inside YAML, not the other way around. As for the surrounding piece of software that is parsing YAML, it's unclear from the question.
Answered By - Seva Alekseyev Answer Checked By - Terry (WPSolving Volunteer)