create bitbucket repository and service in one curl request - shell

Is it possible to create the repository and post service in one request. Here's what I currently have. I'm worried that the 2nd call might happen before the 1st is finished and fail.
curl -u$BB_USER:$BB_PASS -X POST https://api.bitbucket.org/1.0/repositories/ -d "name=$PROJECT_NAME" -d "owner=$BB_Owner" -d 'is_private=1' -d 'scm=git'
curl -u$BB_USER:$BB_PASS -X POST https://api.bitbucket.org/1.0/repositories/$BB_Owner/$PROJECT_FOLDER/services -d type=POST -d URL=$POST_HOOK_URL

Chain them with '&&' so that the second command executes only if the first command completed successfully.
curl -u$BB_USER:$BB_PASS -X POST https://api.bitbucket.org/1.0/repositories/ -d "name=$PROJECT_NAME" -d "owner=$BB_Owner" -d 'is_private=1' -d 'scm=git' && curl -u$BB_USER:$BB_PASS -X POST https://api.bitbucket.org/1.0/repositories/$BB_Owner/$PROJECT_FOLDER/services -d type=POST -d URL=$POST_HOOK_URL

Related

Redirect a cURL response to a cURL that POSTs, but not through a file

I 'd like to post directly a json object from a url(json) to another url
so the command goes as follows:
curl "<resource_link>.json" -o sample.json
curl -X POST "<my_link>" "Content-type: application/json" -d #sample.json
I 'd like to avoid this, so what is the solution? Is it something like that?
curl -X POST "<my_link>" "Content-type: application/json" -d "curl <resource_link>.json"
But it does not work? Also, this one post Stream cURL response to another cURL command posting the result
does not explain thouroughly and it is not working
Yes,
curl
manual explains the '#' but it does not explain about using another curl
Alternatievely, if I could save somewhere temporarily the 1st cURL response and use it in the other command(but not in a file)
You don't want -x POST in there so let's start with dropping that.
Send the results from the first transfer to stdout by not using -o, or telling -o to use stdout with -o-, and
Make sure your second transfer accepts the data to send on stdin, by using -d#-.
curl "<link>.json" | curl "<link2>" -H "Content-type: application/json" -d #-
With curl 7.82.0 and later
Starting with curl 7.82.0 you can do it even easier with the new --json option:
curl "<link>.json" | curl "<link2>" --json #-

For loop from file with multiple columns-BASH

i have following text file (output.txt)
TECH-746 TECH 10400
TECH-747 TECH 10400
i need to read all columns and pass it to 3 variables and then submit it to curl command. While read simple won't work with curl (don't know why) so i need to use for loop (it works with curl), can i use one for loop or need to nest multiple ones
for project in `cat output.txt`; do
echo $project
curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"TECH\"},\"parent\":{\"key\":\"$project\"},\"summary\":\"test",\"description\":\"test.\",\"issuetype\":{\"name\":\"Sub-task\"}}}" -H "Content-Type:application/json" --silent https://jira.company.com/rest/api/latest/issue/ >/dev/null
code above works, so i just want to "extend" to to include all other columns in file
while read can pull a line into distinct variables.
while read project col2 col3
do
curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"TECH\"},\"parent\":{\"key\":\"$project\"},\"summary\":\"test",\"description\":\"test.\",\"issuetype\":{\"name\":\"Sub-task\"}}}" -H "Content-Type:application/json" --silent https://jira.company.com/rest/api/latest/issue/ >/dev/null
done < sourcefile.txt
EDIT:
The curl command also misses escaping one quote, compare the two lines below, the first one is the original, the second one is the one I've corrected.
curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"TECH\"},\"parent\":{\"key\":\"$project\"},\"summary\":\"test",\"description\":\"test.\",\"issuetype\":{\"name\":\"Sub-task\"}}}" -H "Content-Type:application/json" --silent https://jira.company.com/rest/api/latest/issue/ >/dev/null
curl -D- -u user:pass -X POST --data "{\"fields\":{\"project\":{\"key\":\"TECH\"},\"parent\":{\"key\":\"$project\"},\"summary\":\"test\",\"description\":\"test.\",\"issuetype\":{\"name\":\"Sub-task\"}}}" -H "Content-Type:application/json" --silent https://jira.company.com/rest/api/latest/issue/ >/dev/null

How to upload source version to Azure Setting using curl?

My objective is simple: get hold of the last commit hash when I run my app
attempts:
I started to use git-last-commit package but where the app run, it's a normal directory, and the repository is outside this folder
/config
/deployments
/diagnostics
/ipaddr_0
/locks
/repository
/wwwroot
the website runs inside wwwroot and git repo is in repository. I couldn't get hold of it programmatically.
So I tried the Kudu API and it's as easy as a curl POST ... but how can I pass the commit has as a curl data?
I've tried:
$ git log -n1 --pretty=format:"%H" | curl -X POST -H 'Content-Type: application/json' https://$AZURE_LOGIN:$AZURE_PASS#$AZURE_APPNAME.scm.azurewebsites.net/api/settings -d '{ "SOURCE_VERSION":"&> /dev/stdin" }'
and
$ git log -n1 --pretty=format:"%H" | curl -X POST -H 'Content-Type: application/json' https://$AZURE_LOGIN:$AZURE_PASS#$AZURE_APPNAME.scm.azurewebsites.net/api/settings -d '{ "SOURCE_VERSION":"#d" }'
only to find that it sends literally what I write and not the piped value
The idea was to have this as a Bitbucket pipeline step to be executed for every deployment...
Does any of you have some trick to accomplish this?

Entering Password Automatically for Stripe From Bash Script

I am using Stripe's Curl API to create subscriptions.
My bash script looks like this
#!/bin/bash
set pass MyPasword123
curl https://api.stripe.com/v1/customers -u sk_test_BQokikJOvBiI2HlWgH4olfQ2 -d card[number]=4242424242424242 -d card[exp_month]=12 -d card[exp_year]=2016 -d card[cvc]=123 -d plan=EarlyAdopter -d email=test#gmail.com
expect -re "Enter host password for user 'sk_test_BQokikJOvBiI2HlWgH4olfQ2:':"
send "${pass}\r"
This does now work.
How do I enter automatically a password for the Stripe Curl API?
Thanks...
The issue here is that you are only passing the API key but you're missing the : at the end. This is mentioned in the documentation about the Authentication. It should be like this:
curl https://api.stripe.com/v1/customers \
-u sk_test_XXX: \
-d card[number]=4242424242424242 \
-d card[exp_month]=12 \
-d card[exp_year]=2016 \
-d card[cvc]=123 \
-d plan=EarlyAdopter \
-d email=test#gmail.com

< was unexpected at this time. from curl command line when posting input data as an xml to rest service

when i post a raw string as an input to JSON REST Service call it is executing ex:
curl -d "{\"input1\": \"as\", \"input2\": \"ad\"}" -i -X POST -H "Content-Type:application/json" http://localhost/rtygies/Service1.svc/rest/receivedata1
But when i am posting as an xml as input it is giveng error as below:
curl -d "{\"input1\": \"<xml></xml>\", \"input2\": \"<xml></xml>\"}" -i -X POST -H "Content-Type:application/json" http://localhost/rtygies/Service1.svc/rest/receivedata1
Error: < was unexpected at this time
I am using curl in windows.
can any one say how to post xml as a string input to Rest service in JSON format from curl
Actually, I don't know what is the case,
but I got an error said < is unexpected this time
when I tried the following command (on windows):
curl -u admin:password -XPOST -H 'Content-type: text/xml' -d '<namespace><prefix>newWorkspace</prefix><uri>http://geoserver.org</uri></namespace>' http://localhost:8080/geoserver/rest/namespaces
Then I changed the single quote into double quotes and it worked.
Redirection symbols can be escaped by "
Try using
curl -d "{\"input1\": \""<xml></xml>"\", \"input2\": \""<xml></xml>"\"}" -i -X POST -H "Content-Type:application/json" http://localhost/rtygies/Service1.svc/rest/receivedata1
I had no luck with double-quotes, however escaping < and > with ^ worked for me.
So your curl becomes..
curl -d "{\"input1\": \"^<xml^>^</xml^>\", \"input2\": \"^<xml^>^</xml^>\"}" -i -X POST -H "Content-Type:application/json" http://localhost/rtygies/Service1.svc/rest/receivedata1

Resources