I need to create a Team repository usign Bitbucket's API.
To create a user repository I use to do so:
$ curl -k -X POST -u username:passwd "https://api.bitbucket.org/1.0/repositories" -d "name=myrep"
How would I do the same but for a team?
This explains how it works with the repositories endpoint of API 2:
$ team=myteam
$ repo=repository
$ curl -X POST -v -u username:password -H "Content-Type: application/json" \
https://api.bitbucket.org/2.0/repositories/${team}/${repo} \
-d '{"scm": "git", "is_private": "true", "fork_policy": "no_public_forks" }'
The difference from API 1 regarding how the data (-d) is handled is that API2 uses JSON format.
Related
I am keep on getting invalid_payload and not able to trigger email to Slack channel.
send_email:
stage:notify
when:always
variables:
PASSED_COUNT: "'{\"passed\":1}'"
DEPLOY_CURL_COMMAND: 'curl -X POST -H "Content-type:application/json" --data $PASSED_COUNT https://hooks.slack.com/services/xxxxx/xxxxxxx/..'
script:
- echo "Testing Platform"
- echo $DEPLOY_CURL_COMMAND
- 'eval "$DEPLOY_CURL_COMMAND"'
- curl -X POST -H 'Content-type:application/json' --data '{"text":"'$PASSED_COUNT'"}' https://hooks.slack.com/services/xxxxx/xxxxxxx/..'
When I upload artifact to the ApiCurio registry using UI it works fine but if I use CURL for the same artifact, Documentation tab is empty. Any ideas?
I use:
curl -X POST -H "Content-type: application/json" -H "X-Registry-ArtifactType: OPENAPI" -H "X-Registry-ArtifactId: test" --data "{$body}" http://registry:8080/api/artifacts
should use "$body" instead of "{$body}"
I am using rest API to run manual jobs in GitLab CI. When i start a manual job from UI I am able to define custom variables that i can use during the job. How can i define them when running job through API?
Could not find any documentation on it. Or not even a single question in forums.
This is how i currently run my job
curl -k --request POST --header "PRIVATE-TOKEN: abc" https://mygit.com/api/v4/projects/17/jobs/1956/play
I tried adding:
--form variables[TEST]=hello
But this didnt work.
Edit:
A bit more information on what im doing. So my pipeline has two stages. Build and deploy. On each commit I want build to run once and then i want to be able to deploy this result to multiple different servers. Because the server list is dynamic and there are a lot of them I want to have the IP address of the server as an variable I can give to my deploy job.
Instead of starting a job you can start a pipeline and set the variables from there. Here's an example of how to do this from the GitLab documentation:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
--header "Content-Type: application/json" \
--data '{ "ref": "master", "variables": [ {"key": "VAR1", "value": "hello"}, {"key": "VAR2", "value": "world"} ] }' \
"https://gitlab.example.com/api/v4/projects/169/pipeline"
This is the way how I'm using it, didn't find a way to use API tokens for it though.
curl -X POST \
-F token=xxxxxxxxxxxxxxxx \
-F "ref=some_branch" \
-F "variables[VAR1]=abc" \
-F "variables[VAR2]=cde" \
"https://example.gitlab.com/api/v4/projects/312/trigger/pipeline"
Where -F "variables[VAR1]=abc" for example is set in .gitlab-ci.yml.
only:
variables:
- $VAR1
The idea was to create some manual CI jobs and tell the devs they can run them via API call, but since I can only use the project token here, it's absolutely not secure.
It would be really handy to run it via
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>"
Passing variables is documented in gitlab-org/gitlab issue 2772, but more about triggering pipeline (not job)
See if that syntax would work, for trigger variables (syntax variables[xxx]=yyy):
# gitlab-ci.yml
build:
script:
- curl --request POST --form "variables[PRE_CI_PIPELINE_SOURCE]=$CI_PIPELINE_SOURCE" --form "token=$CI_JOB_TOKEN" --form ref=master http://192.168.10.3:3001/api/v4/projects/13/trigger/pipeline
Or simply for regular variables --form key=value:
curl --request POST --form "token=$CI_JOB_TOKEN" --form ref=master https://gitlab.example.com/api/v4/projects/9/trigger/pipeline
It looks like that as of Jan 25, 2021 this feature not yet supported. There is a feature request I found here: https://gitlab.com/gitlab-org/gitlab/-/issues/37267
Update 2022-03:
After you create a trigger token, and create trigger_pipeline step in pipeline, like this
trigger_pipeline:
tags:
image: alpine:latest
stage: deploy
script:
only:
variables:
- $MANUAL
you can use it to trigger pipelines with a tool that can access the API
curl --request POST \
--form token=TOKEN \
--form ref=main \
--form "variables[MANUAL]=true" \
"https://gitlab.example.com/api/v4/projects/123456/trigger/pipeline"
or a webhook:
https://gitlab.example.com/api/v4/projects/123456/ref/<ref_name>/trigger/pipeline?token=<token>
for example for manual run.
When following the steps described here: https://forge.autodesk.com/en/docs/design-automation/v3/tutorials/revit/step4-publish-appbundle/#step-3-upload-the-appbundle I get an Aws specific error.
<Error><Code>AccessDenied</Code><Message>No AWSAccessKey was presented.</Message>
I have verified my request but it seems that both the header and all form data has been set correctly, as described in this example:
curl -X POST \
https://dasprod-store.s3.amazonaws.com \
-H 'Cache-Control: no-cache' \
-F key=apps/Revit/DeleteWallsApp/1 \
-F content-type=application/octet-stream \
-F policy=eyJleHBpcmF0aW9uIjoiMjAxOC... (truncated) \
-F success_action_status=200 \
-F success_action_redirect= \
-F x-amz-signature=6c68268e23ecb8452... (truncated) \
-F x-amz-credential=ASIAQ2W... (truncated) \
-F x-amz-algorithm=AWS4-HMAC-SHA256 \
-F x-amz-date=20180810... (truncated) \
-F x-amz-server-side-encryption=AES256 \
-F 'x-amz-security-token=FQoGZXIvYXdzEPj//////////wEaDHavu... (truncated)' \
-F 'file=#path/to/your/app/zip'
Of course, all values have been replaced with the response received from
curl -X POST \
https://developer.api.autodesk.com/da/us-east/v3/appbundles \
-H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
-H 'Content-Type: application/json' \
-d '{
"id": "DeleteWallsApp",
"engine": "Autodesk.Revit+2018",
"description": "Delete Walls AppBundle based on Revit 2018"
}'
Now, since this is an AWS specific error, maybe there have been some changes to the AWS api and are the examples given in the forge documentation not up to date?
This seemed to be a client issue.
I am using the request npm package in node.js and did set the formData as part of the form attribute, instead of the formData attribute.
const request = require('request-promise');
return request.post(uploadParameters.endpointURL, {
headers: {
'Content-Type': 'multipart/form-data',
'Cache-Control': 'no-cache'
},
formData: { // use formData instead of form
...uploadParameters.formData,
file: fs.createReadStream(EXPECTED_APPBUNDLE_PATH)
}
})
Glad you figured out what was going on :)
If you want a nodejs sample/example for Design Automation, you can take a look at this repository. Even tough it has been built for 3ds Max, the Design Automation concepts are still the same.
https://github.com/Autodesk-Forge/design.automation.3dsmax-nodejs-basic/blob/master/createAndUploadApp.js
Hopefully, something in there can be useful to you.
Google Analytics's new "Core Reporting API" (version 3.0) "recommend[s] using OAuth 2.0 to authorize requests" (citation). Its documentation, though, is very unclear about how to do that. (It says "When you create your application, you register it with Google" (citation), but does a shell script count as an "application"?? If so, I should register the bash script at the "APIs Console", which doesn't give any guidance on how to do so.) Using Analytics' version 2.3, I run a bash script:
#!/bin/bash
# generates an XML file
googleAuth="$(curl https://www.google.com/accounts/ClientLogin -s \
-d Email=foo \
-d Passwd=bar \
-d accountType=GOOGLE \
-d source=curl-dataFeed-v2 \
-d service=analytics \
| awk /Auth=.*/)"
# ...
feedUri="https://www.google.com/analytics/feeds/data\
?ids=$table\
&start-date=$SD\
&end-date=$ED\
&dimensions=baz\
&metrics=xyzzy\
&prettyprint=true"
# ...
curl $feedUri --silent \
--header "Authorization: GoogleLogin $googleAuth" \
--header "GData-Version: 2" \
| awk # ...
How would I do something like this — a script that grabs whatever login token I need and sends it back — for the new Analytics?
(Incidentally, yes, I realize the results will be JSON, not XML.)
Here is a sample script
googleAuth="$(curl https://www.google.com/accounts/ClientLogin -s \
-d Email=$USER_EMAIL \
-d Passwd=$USER_PASS \
-d accountType=GOOGLE \
-d source=curl-accountFeed-v1 \
-d service=analytics \
| grep "Auth=" | cut -d"=" -f2)"
feedUri="https://www.googleapis.com/analytics/v3/data/ga\
?start-date=$START_DATE\
&end-date=$END_DATE\
&ids=ga:$PROFILE_ID\
&dimensions=ga:userType\
&metrics=ga:users\
&max-results=50\
&prettyprint=false"
curl $feedUri -s --header "Authorization: GoogleLogin auth=$googleAuth"