Bitbucket API 2 - create repository in a team project - bitbucket-api

I have a team on my bitbucket account, myteam, which contains a project named mainproject. Whenever I want to create a repository inside I only need to execute this command line:
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo1" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks"}'
This works. However the issue arises when I create a second project, named secondproject. How am I supposed to tell the API to which project the repository should belong?
I tried specifying the project information in the data (-d):
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo2" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"name": "secondproject"} }'
or with the key parameter:
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo2" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks", "project": {"key": "SEC"} }'
This will create the repository repo2 in the project mainproject.
I tried using the uuid but the same occurs, repo is created in the mainproject.
I tried putting the project name in the link:
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/secondproject/repo1" -d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks"
...
{"error": {"message": "Resource not found", "detail": "There is no API hosted at this URL.\n\nFor information about our API's, please refer to the documentation at: https://confluence.atlassian.com/x/IYBGDQ"}}
How can I specify which project the repository I want to create belongs to?
I am not looking for a GUI solution, I want to stick to the command line as I need to automatize the creation of repositories this way.

The content type has to be specified to curl with this argument: -H "Content-Type: application/json". Then the json data would be accessed normally. So the final command would look like this:
$ curl -X POST -v -u myaccount:passwd "https://api.bitbucket.org/2.0/repositories/myteam/repo2" -H "Content-Type: application/json" -d '{"has_wiki": true, "is_private": true, "project": {"key": "PRJ_KEY"}}'

Related

How to create and start a XL Release release with a http request?

I need help because I'm not good with HTTP Requests.
I am trying to create a Release on my XL Release server with a HTTP request. Right now I'm doing it with Curl, in a batch file, like that
curl "https://{ID}:{password}#{IP}:{port}/api/v1/templates/Applications/Folder{IDFolder}/create" -i -X POST -H 'Content-Type:application/json' -H 'Accept:application/json' -d %0\..\ReleaseConfig.json
The data file, which is in the same directory as the script, I'm calling is a json like that :
{ "releaseTitle" : "API Test", "releaseVariables" : { }, "releasePasswordVariables" : { }, "scheduledStartDate" : null, "autoStart" : false }
The problem is, I get an error like that while executing my command :
RESTEASY003065: Cannot consume content type
Do you have any idea what can help my case ?
Thanks
By looking at your filename, it seems that you are on Windows. I suspect you can't escape your Content-type with quote, you have to use double quotes.
Also, to pass a file as POST data, you have to use an #, like this:
curl "https://{ID}:{password}#{IP}:{port}/api/v1/templates/Applications/Folder{IDFolder}/create" -i -X POST -H "Content-Type:application/json" -H "Accept:application/json" -d #%0\..\ReleaseConfig.json

Why can't the exported cURLS be imported back to POSTMAN?

The latest update of the POSTMAN (7.16) doesn't seem to understand the cURL when importing them.
Here is a cURL exported by POSTMAN itself via the "Code" option.
curl -L -X POST 'https://example.com/example/' \
-H 'Content-Type: application/json' \
--data-raw '{
"requestFields":{
"address":"123, Main Street",
"ping":false
}
}'
But when this cURLis is tried to be imported to POSTMAN again, it doesn't populate the Body area of the request.
Is there a workaround?

Create multiple artifactory repositories from json

I want to automate the process of importing existing repositories structure from another Artifactory through .json file.
So far, I have managed to make single repo from json with the following command.
curl -X PUT --insecure -u admin -H "Content-type: application/json" -T repository-config.json "https://artifactory.test.net/artifactory/api/repositories/acqbo-docker-release-local"
Is there a way to import multiple/array of repositories from a single json file and a single curl?
Ended up writing my own bash script for this purpose.
you will have to make a file with the repositories you want to copy:
#!/bin/bash
#############
# This script copies the repository structure from one Artifactory server to another
# repos.list file is required to have repositories that we want to copy, each in new line.
# user with the admin rights is necessary
#############
#Where to copy repos from and to
ARTIFACTORY_SOURCE="https://source.group.net/artifactory/api/repositories/"
ARTIFACTORY_DESTINATION="https://destination.group.net/artifactory/api/repositories/"
NOLINES=$(wc -l < repos.list) #get total nuber of lines in repos.line
COUNTER=1 #Set the counter to 1
while [ $COUNTER -le $NOLINES ] #loops times number of lines in the repos.line
do
REPONAME=$(awk "NR==$COUNTER" repos.list) #get only repo name, line by line
curl -GET --insecure -u admin:adminpass "$ARTIFACTORY_SOURCE$REPONAME" > xrep.json #Obtain data from Artifactory source, repo by repo, and writes it to the xrep.json
curl -X PUT --insecure -u admin:adminpass -H "Content-type: application/json" -T xrep.json "$ARTIFACTORY_DESTINATION$REPONAME" #Sends data from json to the destination Artifactory server
#print in blue color
printf "\e[1;34m$COUNTER repo done\n\e[0m"
((COUNTER++))
done
printf "\e[1;34mAll repos exported!\n\e[0m"

OpenStack Swift cannot use bulk operation to auto extract tar file

I want to upload many files with a single operation in OpenStack Swift. I find the middleware -- Bulk Operations which can auto extract files from tar compressed file. However, I failed to extract the files from the tar.
I PUT the tar file use the bulk operation like this:
curl -X PUT http://127.0.0.1:8080/v1/AUTH_test/ContainerName/$?extract-archive=tar \
-T theTarName.tar \
-H "Content-Type: text/plain" \
-H "X-Auth-Token: token"
I am sure that the storageURL, tar file path, and token is accurate. But, I didn't get any responses(successes or errors). When I show the objects in the container, I find just one object named 0extract-archive=tar was uploaded, but the files in the tar were not extracted.
I want to know how to extract the tar automatically in OpenStack Swift and all of the files in the tar can be displayed in the container.
Thanks in advance.
The issue is the $? part. $? refers to the exit code of the last command in bash (http://tldp.org/LDP/abs/html/exit-status.html), which I suspect you're using.
If you'd like to use $ as the archive prefix, consider escaping it with \:
$ curl -X PUT \
"http://127.0.0.1:8080/v1/AUTH_test/container/\$?extract-archive=tar" \
-T test.tar \
-H "X-Auth-Token: <token>"
You should get the following output:
Number Files Created: 3
Response Body:
Response Status: 201 Created
Errors:

Fiware Keystone API Create User

We are trying to create users in Fiware IDM using Keystone Identity API.
We are sending the following curl command
curl -s \
-H "X-Auth-Token: e746971040657101bb1e" \
-H "Content-Type: application/json" \
-d '{"user": {"name": "newuser", "password": "changeme"}}' \
http://localhost:35357/v3/users | python -mjson.tool
The token we have used is the one configured in keystone.conf
admin_token=e746971040657101bb1e
But the result we are getting is the following
{
"error": {
"code": 401,
"message": "The request you have made requires authentication.",
"title": "Unauthorized"
}
}
Does anyone have an idea about what can happen?
A couple of ideas for you.
One is that the port value 35357 is not for the admin API calls, it's intended for user calls.
Also since you are using the v3 API I believe that the token can't be used when creating a user unless you are indicating a domain.
However I can't tell from your curl command what action you are trying to do.

Resources