Hello I want to use the API approach to show the jenkins build status with curl as stated here: https://developer.atlassian.com/server/bitbucket/how-tos/updating-build-status-for-commits/
Assembled that:
curl -u username:'password' -H "Content-Type: application/json" -X POST https://tools.my.repo.com/bitbucket/rest/build-status/1.0/commits/620d293ed88412e45c58aae537b8765be2e8d148 -d #build0.json`
Where my build json contains:
{
"state": "SUCCESSFUL",
"key": "8",
"name": "feature/branch",
"url": "https://my.jenkins.placeholder/job/Plugintest/",
"description": "Changes by Umbert Eco"
}
I need to have that in one line...Is it possible?
Yes!! Try framing the curl in this way
curl -u username:password -H "Content-Type: application/json" -X POST https://tools.my.repo.com/bitbucket/rest/build-status/1.0/commits/620d293ed88412e45c58aae537b8765be2e8d148 -d '{\"state\": \"SUCCESSFUL\",\"key\": \"8\",\"name\": \"feature/branch\",\"url\": \"https://my.jenkins.placeholder/job/Plugintest\",\"description\": \"Changes by Umbert Eco\"}'
Related
Curl - Encode file as url query
I'm trying to send message to Amazon SQS queue with payload read from file using curl
So far I've got working curl to send message to queue but with harcoded value like:
curl --request POST \
--url 'http://localhost:9324/queue/price-import?Action=SendMessage&MessageBody=%7B%0A%09%22id%22%3A%20%22f23399af-a384-4ed3-bac0-386a01804d83%22%2C%0A%09%22de%22%3A%20%7B%0A%09%09%22price%22%3A%2010.59%0A%09%7D%2C%0A%09%22nl%22%3A%20%7B%0A%09%09%22price%22%3A%20107.99%0A%09%7D%2C%0A%09%22pl%22%3A%20%7B%0A%09%09%22price%22%3A%2012.15%0A%09%7D%0A%7D'
And payload I send is:
{
"id": "f23399af-a384-4ed3-bac0-386a01804d83",
"de": {
"price": 10.59
},
"nl": {
"price": 107.99
},
"pl": {
"price": 12.15
}
}
How can I modify this curl to omit harcoded value and instead put path to file with .json extension?
Desired output
curl --request POST \
--data-urlencode http://localhost:9324/queue/price-import?Action=SendMessage&MessageBody=#input.json
What I already tried
curl --request POST -data-urlencode http://localhost:9324/queue/price-import?Action=SendMessage&MessageBody=#input.json
curl --request POST -data-urlencode input.json http://localhost:9324/queue/price-import
curl --request POST -data-urlencode "sendbody#input.json" http://localhost:9324/queue/price-import
curl --request POST --data-urlencode SendBody#input.json --url http://localhost:9324/queue/price-import?Action=SendMessage
Resources I found
Unix cURL POST to specific variable using contents from a file
POSTing a file's contents with CURL
curl.1 the man page
Answering to my own question based on this answer:
How to urlencode data for curl command?
This worked for me:
curl \
--data-urlencode MessageBody#input.json \
--data-urlencode "Action=SendMessage" \
http://localhost:9324/queue/price-import
and my input.json file:
{
"id": "f23399af-a384-4ed3-bac0-386a01804d83",
"de": {
"price": 10.59
},
"nl": {
"price": 107.99
},
"pl": {
"price": 12.15
}
}
I need to call an API where I increment the user ID every time, I have the following in the bash script, but keep getting a Unexpected token ' in JSON at position 2 error. What am I doing wrong?
for ((i=1;i<=5;i++)); do
curl -X POST --header 'Content-Type: application/json' -d "{ 'id': 'person'$i, 'name':
'person', 'info': {} }" 'http://localhost:9999/add'
It is a quoting issue. It is standard for JSON to have double quotes, try this
for ((i=1;i<=5;i++)); do
echo "Adding person"$i
curl -X POST --header 'Content-Type: application/json' --header
'Accept: application/json' --user 'admin' -d '{ "id": "person'$i'", "name":
"person", "info": {} }" 'http://localhost:9999/add'
done
You can use jq, to edit json by shellscript. See this link.
Is it possible to use the Global Instance of Keystone to retrieve registered user profile info?
According to these references: https://github.com/telefonicaid/fiware-pep-steelskin#keystone and Keystone create user and permissions by api, it seems possible if I wish to install an instance by my own. However, what if I wish to use the Global Instance, instead. Is it possible?
For example, I have tested te retrieve some data as indicated below without success:
curl -s -H "X-Auth-Token:cXylpiNyh74V6J9YOlqN2GTzYSmGQa" http://cloud.lab.fiware.org:4730/v2.0/tokens | python -mjson.tool
curl -s -H "X-Auth-Token:cXylpiNyh74V6J9YOlqN2GTzYSmGQa" http://cloud.lab.fiware.org:4730/v3/users/ | python -mjson.tool
curl http://cloud.lab.fiware.org:4730/v3/auth/tokens -H "Content-Type: application/json" -d ' { "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "domain": { "name": "matest" }, "name": "pep_proxy_99c59...", "password": "e3025a286dab..." } } } } }'
Note: I have tried both port: 5000 and 4730.
Any hint will be appreciated.
Users doesn't have permissions to see other users information or to create new users using the API.
However, you can issue tokens from the global keystone using both v2.0 and v3 protocols:
curl -X POST http://130.206.84.8:4730/v2.0/tokens \
-H 'Content-Type: application/json' \
-d "{\"auth\": {\"tenantName\": \"${OS_TENANT_NAME}\",
\"passwordCredentials\": {
\"username\": \"$OS_USERNAME\",
\"password\": \"$OS_PASSWORD\"}}}" | \
jq -r '.access.token.id'
Or issue a token in v3:
curl -v -H "Content-Type: application/json" -d "
{ \"auth\": {
\"identity\": {
\"methods\": [\"password\"],
\"password\": {
\"user\": {
\"name\": \"$OS_USERNAME\",
\"domain\": { \"id\": \"default\" },
\"password\": \"$OS_PASSWORD\"
}
}
}
}
}" http://cloud.lab.fiware.org:4730/v3/auth/tokens 2>&1 \
| grep -i "X-Subject-Token"
There are few things you can do with Keystone itself using these tokens if you are not the admin user (Non admin users obviously have few permissions). However, you coud, for instance query the endpoints:
curl -s -H "X-Auth-Token: $TOKEN_ID" http://130.206.84.8:4730/v3/endpoints
The domains:
curl -s -H "X-Auth-Token: $TOKEN_ID" http://130.206.84.8:4730/v3/domains
During this tutorial: https://github.com/telefonicaid/iotagent-json/blob/master/docs/stepbystep.md
When I execute the curl:
curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Fiware-Service: myHome" -H "Fiware-ServicePath: /environment" -H "Cache-Control: no-cache" -d '{
"value" : "300"
}' 'http://localhost:1026/v1/contextEntities/LivingRoomSensor/attrs/sleepTime'
I'm getting this error response:
{
"orionError" : {
"code" : "400",
"reasonPhrase" : "Bad Request",
"details" : "service not found"
}
}
How to fix this?
Cumps
It seems you are "mixing" URL styles from NGSIv1 and NGSIv2 :) I mean, it should be either:
/v2/entities/LivingRoomSensor/attrs/sleepTime
or
/v1/contextEntities/LivingRoomSensor/attributes/sleepTime
My recomendation is always to use NGSIv2, as it is a more powerfull, flexible and simple version of the context management API that Orion Context Broker provides.
Solved by changing:
localhost:1026/v1/contextEntities/LivingRoomSensor/attrs/…
to
localhost:1026/v1/contextEntities/LivingRoomSensor/attributes/…
I have the following bash script
#!/bin/bash
body=$(cat << EOF
{
"CreatedBy": "$(hostname -f)",
"Id": "$(uuidgen)",
"Type": "TestAlertType",
"AlertCategory": "NonUrgent"
}
EOF
)
curl -H "Content-Type: application/json" -X POST -d $body https://dev.cloudapp.net/v1/
But I get invalid json error on post. What am i missing?
This worked
curl -H "Content-Type: application/json" -X POST -d "$body" https://dev.cloudapp.net/v1/