I'm looking at the JIRA api docs. Does anyone know where I can find these credentials?
-u charlie:charlie \
For the request
curl \
-D- \
-u charlie:charlie \
-X POST \
--data {see below} \
-H "Content-Type: application/json" \
http://localhost:8080/rest/api/2/issue/
I found it. Account Settings-> Security -> Create and Manage api tokens.
Related
I am trying to run the below CURL command to trigger a JENKINS job with huge list of parameters. Job gets submitted , but it does not read my parameters that i sent , instead picks up the defaults.
curl -v -X POST \
'https://jenkins_URL/buildWithParameters?' \
-H 'Content-Type: application/json' \
--user ABC:token \
--form json='{\"parameter\":[{\"name\":\"ACTION\", \"value\":\"ONBOARD_NEWUSECASE"\ } \
,{\"name\":\"Name\", \"value\":\"ABC\"} \
,{\"name\":\"Number\", \"value\":\"123456789\"} \
,{\"name\":\"sample\", \"value\":\"SAMPLE\"} \
,{\"name\":\"A1\", \"value\":\"V1\"} \
,{\"name\":\"A2\", \"value\":\"V2\"} \
,{\"name\":\"A3\", \"value\":\"V3\"} \
]}'
file://policy.json
can someone please help me to fix this ?
Instead of submitting the content as Json you can just pass parameter as query parameters.
Try the following:
curl -X POST -ABC:token "https://jenkins_URL/buildWithParameters?\
ACTION=ONBOARD_NEWUSECASE&\
Name=ABC&\
Number=123456789&\
sample=SAMPLE&\
A1=V1&\
A2=V2&\
A3=V3"
How to authenticate with the V2 API is useful and works.
REPO="https://hub.docker.com/v2"
I'm able to get tokens, list (my) repos and lists their images and tags.
curl --silent \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/repositories/${USERNAME}/
curl --silent \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/repositories/${USERNAME}/${IMAGE}/tags/
I'd like to 'GET MANIFEST' but I'm struggling to get this to work:
https://docs.docker.com/registry/spec/api/#manifest:
curl --silent \
--header "Host: hub.docker.com" \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/repositories/${USERNAME}/${IMAGE}/manifests/
curl --silent \
--header "Host: hub.docker.com" \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/${USERNAME}/${IMAGE}/manifests/
curl --silent \
--header "Host: hub.docker.com" \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/${USERNAME}/${IMAGE}/manifests/${TAG}
I've tried with|without the Host header. With various values for the Host header. But, I'm clearly missing something. I tried pattern-matching against the working endpoints but no joy:
curl --silent \
--header "Authorization: JWT ${TOKEN}" \
${REPO}/repositories/${USERNAME}/${IMAGE}/manifests/
Curiously, this page shows "GET TAGS" seemingly incorrectly as /v2/<name>/tags/list:
https://docs.docker.com/registry/spec/api/#tags
Reviewed:
https://stackoverflow.com/a/45605443/609290
Follow-up
I'm a Googler and have access to Google Container Registry (GCR).
REPO="https://gcr.io/v2/"
On a whim, I just tried 'GET MANIFEST' against GCR and the requests works:
curl --silent \
--request GET \
--user _token:$(gcloud auth print-access-token) \
${REPO}/${PROJECT}/${IMAGE}/manifests/${TAG}
It's quite confusing with all the *.docker.com|io subdomains!
I found registry.hub.docker.com and index.docker.io the most reliable ones.
You can easily query the tags from there, but for the manifests you'll need to get a token for pulling first:
REGISTRY=https://index.docker.io/v2
#REGISTRY="https://registry.hub.docker.com/v2"
#REGISTRY="https://registry.docker.io/v2"
#REGISTRY="https://registry-1.docker.io/v2"
#REGISTRY="https://hub.docker.com/v2"
REPO=library
IMAGE=debian
# Could also be a repo digest
TAG=latest
# Query tags
curl "$REGISTRY/repositories/$REPO/$IMAGE/tags/"
# Query manifest
curl -iL "$REGISTRY/$REPO/$IMAGE/manifests/$TAG"
# HTTP/1.1 401 Unauthorized
# Www-Authenticate: Bearer realm="https://auth.docker.io/token",service="registry.docker.io",scope="repository:library/debian:pull"
TOKEN=$(curl -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPO/$IMAGE:pull" \
| jq --raw-output .token)
curl -LH "Authorization: Bearer ${TOKEN}" "$REGISTRY/$REPO/$IMAGE/manifests/$TAG"
# Some repos seem to return V1 Schemas by default
REPO=nginxinc
IMAGE=nginx-unprivileged
TAG=1.17.2
curl -LH "Authorization: Bearer $(curl -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPO/$IMAGE:pull" | jq --raw-output .token)" \
"$REGISTRY/$REPO/$IMAGE/manifests/$TAG"
# Solution: Set the Accept Header for V2
curl -LH "Authorization: Bearer $(curl -sSL "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$REPO/$IMAGE:pull" | jq --raw-output .token)" \
-H "Accept:application/vnd.docker.distribution.manifest.v2+json" \
"$REGISTRY/$REPO/$IMAGE/manifests/$TAG"
See
this gist for another example and
this repo for a reusable script docker-image-size-curl.sh
Authorization with hub.docker.com works differently and you don't seem to get the manifests from there 🤔
I am using curl command :
curl -X POST --user "apikey:xxx" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--data-binary #profile.json \
"https://gateway-fra.watsonplatform.net/personality-insights/api"
and IBM is giving me response:
x{"code":404,"sub_code":"S00004","error":"Not Found"}%
anyone has idea why?
this is my .json file
https://watson-developer-cloud.github.io/doc-tutorial-downloads/personality-insights/profile.json
Try using the following curl command:
curl -X POST --user "apikey:xxxxxxxx" --header "Content-Type: application/json" --header "Accept: application/json" --data-binary #profile.json "https://gateway-fra.watsonplatform.net/personality-insights/api/v3/profile?version=2017-10-13&consumption_preferences=true&raw_scores=true"
Replace xxxxxxxx with your apikey. Please avoid using real apikey in public in the future. Anyone can use your key. I have edited the question to hide it.
Please follow the API reference for Personality Insights for more info.
I try to launch a Jenkins build via its API using cURL:
#!/usr/bin/env bash
curl \
-i \
--fail \
--show-error \
-s \
-X POST \
-H 'Content-Type:application/json' \
-H 'Accept:application/json' \
--form json='{"parameter": [{"name":"COMPOSE_FULL_NAME", "value": "/redacted/docker-compose-prod.yml"}, {"name":"BRANCH", "value": "prod"}, {"name":"AD_USER", "value": "redacted"}, {"name":"AD_PASSWORD", "value": "redacted"}}]}' \
-u redactedUser:redactedToken \
-k \
https://jenkins-dck.redacted/job/elr-156344/job/stack_deploy/build \
and this is what I get:
curl: (22) The requested URL returned error: 400 Nothing is submitted
I tried several ways of passing POST data, like using -d or --data-urlencode 'json={ but with no success so far.
Any idea what's going on ? the message doesn't say much and I can't access the logs of the jenkins backend.
ok, found it, you first need to disregard the docs here: https://wiki.jenkins.io/display/JENKINS/Remote+access+API. The proper method is described at https://wiki.jenkins.io/display/JENKINS/Parameterized+Build
use this API endpoint:
https://jenkins-dck.redacted/job/elr-156344/job/stack_deploy/buildWithParameters?param1=urlencode¶m2=urlencoded
Don't forget to quote the url in the CURL quote, since bash will mess with & symbols.
working example:
#!/usr/bin/env bash
curl \
-i \
--fail \
--show-error \
-s \
-X POST \
-H 'Content-Type:application/json' \
-H 'Accept:application/json' \
-u redactedUser:redactedToken \
-k \
"https://jenkins-dck.redacted/job/elr-156344/job/stack_deploy/buildWithParameters?BRANCH=prod&AD_USER=$SERVICE_ACCOUNT"
I am trying to call a curl command with the sh command, but I would get "errors parsing JSON" no matter what I try.
sh """
curl -s -X POST \
--url www.example.com
--data \"{\'state\': \'failure\'}\"
"""
Problem:
I think you added terminators incorrectly.
Solution:
Simply use this format. It should work fine.
curl -s -X POST --header "Content-Type: application/json" \
--request POST \
--data '{"state":"failure"}' \
http://www.example.com
The JSON standard requires double quotes around key value pairs. Looks like in your example your missing a \ after the --url as well.
Try:
sh '''
curl -s -X POST \
-H \'Content-type: application/json\' \
--url www.example.com \
--data \'{"state": "failure"}\'
'''
If you end up needing to use String interpolation then
sh """
curl -s -X POST \
-H 'Content-type: application/json' \
--url www.example.com \
--data '{\"state\": \"status\"}'
"""