Bitbucket repository creations by api - bitbucket

after reading the doc https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories .
Seems this API is for reading the info of existing repos.
Is there any API for repo creation?

Check out the POST of repo_slug
/2.0/repositories/{workspace}/{repo_slug}
With:
repo_slug string : This can either be the repository slug or the UUID of the repository, surrounded by curly-braces, for example: {repository UUID}.
workspace string : This can either be the workspace ID (slug) or the workspace UUID surrounded by curly-braces, for example: {workspace UUID}.
Creates a new repository.
Note: In order to set the project for the newly created repository, pass in either the project key or the project UUID as part of the request body as shown in the examples below:
$ curl -X POST -H "Content-Type: application/json" -d '{
"scm": "git",
"project": {
"key": "MARS"
}
}' https://api.bitbucket.org/2.0/repositories/teamsinspace/hablanding
or
$ curl -X POST -H "Content-Type: application/json" -d '{
"scm": "git",
"project": {
"key": "{ba516952-992a-4c2d-acbd-17d502922f96}"
}
}' https://api.bitbucket.org/2.0/repositories/teamsinspace/hablanding
The project must be assigned for all repositories. If the project is not provided, the repository is automatically assigned to the oldest project in the workspace.
Note: In the examples above, the workspace ID teamsinspace, and/or the repository name hablanding can be replaced by UUIDs.
For BitBucket server, that would be here, as illustrated in this gist:
/rest/api/1.0/projects/{projectKey}/repos
But V1 API was deprecated in 2018.

Related

How to create multiple branch restrictions using Bitbucket api?

I'm trying to automate the branch permissions setup using the bitbucket api but when I try to add multiple rules it doesn't overwrite the old rule (in case it exists). I'm creating 2 rules for a repository for one branch but if I re-run the api again with a little change in the rule, it will add the rule I added, instead of editing it the current rule.
I run this call:
curl -X POST -v -u "username:secret" -H "Content-Type: application/vnd.atl.bitbucket.bulk+json" https://bitbucket.example.com/rest/branch-permissions/2.0/projects/myproj/repos/myrepo/restrictions -d '[{ "type": "read-only","matcher": {"id": "master","displayId": "master","type": {"id":"PATTERN","name": "Pattern"}},"users": ["my.user"],"groups": ["StashAdmins"]},{ "type": "no-deletes","matcher": {"id": "master","displayId": "master","type": { "id":"PATTERN","name": "Pattern"}},"users": ["user.my"],"groups": []}]'
Then I wanted to overwrite the current branch permissions so I changed the first rule from read-only to pull-request-only, so I run :
curl -X POST -v -u "username:secret" -H "Content-Type: application/vnd.atl.bitbucket.bulk+json" https://bitbucket.example.com/rest/branch-permissions/2.0/projects/myproj/repos/myrepo/restrictions -d '[{ "type": "pull-request-only","matcher": {"id": "master","displayId": "master","type": {"id":"PATTERN","name": "Pattern"}},"users": ["my.user"],"groups": ["StashAdmins"]},{ "type": "no-deletes","matcher": {"id": "master","displayId": "master","type": { "id":"PATTERN","name": "Pattern"}},"users": ["user.my"],"groups": []}]'
but it added the new rule (pull-request-only) instead of editing the whole rule.
Does anyone know how to forces overwrite the branch restriction rule?
With this Rest Api endpoint you can just create new restrictions as you can have several ones per repository and/or project.
See here for more: https://docs.atlassian.com/bitbucket-server/rest/6.4.0/bitbucket-ref-restriction-rest.html#idp1
You first need to delete all restrictions which were created before and then post a new one. To get all restrictions per repository you will need to use this endpoint:
GET /rest/branch-permissions/2.0/projects/{projectKey}/repos/{repositorySlug}/restrictions
https://docs.atlassian.com/bitbucket-server/rest/6.4.0/bitbucket-ref-restriction-rest.html#idp3
And then you can delete them one by one with this one:
DELETE /rest/branch-permissions/2.0/projects/{projectKey}/repos/{repositorySlug}/restrictions/{id}
https://docs.atlassian.com/bitbucket-server/rest/6.4.0/bitbucket-ref-restriction-rest.html#idp6

What is the NGSI v2 endpoint for mimicking IoT Agent commands?

When testing commands Southbound, I am currently using the NGSI v1 endpoint as shown:
curl -X POST \
'http://{{iot-agent}}/v1/updateContext' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"contextElements": [
{
"type": "Bell",
"isPattern": "false",
"id": "urn:ngsi-ld:Bell:001",
"attributes": [
{
"name": "ring",
"type": "command",
"value": ""
}
]
}
],
"updateAction": "UPDATE"
}'
As you can see this is an NGSI v1 request. According to this presentation on Slideshare (slide 16) use of NGSI v1 is discouraged - I would like to replace this with an NGSI v2 request. I believe that all IoT Agents are now NGSI v2 capable, however I have been unable to find the details of the replacement NGSI v2 request within the documentation.
So the question is what is the equivalent cUrl command to mimic a command from Orion using NGSI v2?
In this document you can see a good reference on how to send commands using the NGSIv2 API:
If you take a look to the previous device example, you can find that a "ping" command was defined. Any update on this attribute “Ping” at the NGSI entity in the ContextBroker will send a command to your device. For instance, to send the "Ping" command with value "Ping request" you could use the following operation in the ContextBroker API:
PUT /v2/entities/[ENTITY_ID]/attrs/ping
{
"value": "Ping request",
"type": "command"
}
ContextBroker API is quite flexible and allows to update an attribute in several ways. Please have a look to the NGSIv2 specification for details.
Important note: don't use operations in the NGSI API with creation semantics. Otherwise, the entity/attribute will be created locally to ContextBroker and the command will not progress to the device (and you will need to delete the created entity/attribute if you want to make it to work again). Thus, the following operations must not be used:
POST /v2/entities
PUT /v2/entities
POST /v2/op/entites with actionType append, appendStrict or replace
POST /v1/updateContext with actionType APPEND, APPEND_STRICT or REPLACE
EDIT: all the above refers to the Orion endpoint used by final client to send commands. #jason-fox has clarified that question refers to the IOTA endpoint that receives commands request from Orion (it should have been evident by the {{iot-agent}}, but I missed that part sorry :)
The Orion-to-IOTA communication for commands is based on the registration-forwarding mechanism. Currently, Orion always uses NGSIv1 to forward updates (even in the case the client uses NGSIv2 updates). In the future, we envision the usage of NGSIv2 but in order to achieve this, first we need:
To complete the Context Source Forwarding Specification, based on NGSIv2. It is currently under discussion in this PR. Feedback is welcome as comments to that PR!
To implement forwarding based in Context Source Forwarding Specification in Orion
To implement NGSIv2 endpoint compliant with Context Source Forwarding Specification in the IOTAs.
While the above gets completed, the only mechanism is the current one based in NGSIv1. However, note the Orion-IOTA interaction is internal to platform component and final client could base all their interactions to the platform (in particular, to the Orion endpoint) on NGSIv2, so this is not a big issue.
The Context Source Forwarding Specification, based on NGSIv2 is now completed and the old /v1 endpoint has been deprecated. According to the discussions of the associated Support for NGSIv2 issue, the correct request to send is as follows:
curl -iX POST \
http://localhost:4041/v2/op/update \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"actionType": "update",
"entities": [
{
"type": "Bell",
"id": "urn:ngsi-ld:Bell:001",
"ring" : {
"type": "command",
"value": ""
}
}
]
}'

How to query predictionio for a particular app

I have created multiple apps in predictionio.
While inserting events in predictionio, there a parameter accessKey (associated to app) which is passed.
Whereas for queries.json, couldn't find the accessKey parameter.
Sample below:
curl -H "Content-Type: application/json" \
-d '{ "items": ["i1", "i3"], "num": 10, "categories" : ["c4", "c3"], "blackList": ["i21", "i26", "i40"] }' \
http://localhost:8000/queries.json
{"itemScores":[{"item":"i39","score":1.0773502691896257},{"item":"i44","score":1.0773502691896257},{"item":"i14","score":1.0773502691896257},{"item":"i45","score":0.7886751345948129},{"item":"i47","score":0.7618016810571367},{"item":"i6","score":0.7618016810571367},{"item":"i28","score":0.7618016810571367},{"item":"i9","score":0.7618016810571367},{"item":"i29","score":0.6220084679281463},{"item":"i30","score":0.5386751345948129}]}
Now, how to query data for a particular app?

firebase dynamic link created programmatically in swift doesn't work, no domain

I have configured firebase project with dynamic link, I have domain for DL. But when I creating shroten link programmatically then I get an error. This error I receive for target test and debug of project, but same code is using for release app and for it dynamic link works. Each project target have own firebase project and domain. I don't know why works only release version ?
Your project does not own Dynamic Links domain
Try this command line with your bundleID, app_code and API key:
curl -X POST --dump-header - -H "X-Ios-Bundle-Identifier:
REPLACE_THIS_WITH_YOUR_BUNDLE_ID” -H "Accept: application/json" -H
"Content-Type: application/json" -d
"{\"longDynamicLink\":\"https://REPLACE_THIS_WITH_YOUR_APP_CODE.app.goo.gl/?link=https%3A%2F%2Fwww%2Egoogle%2Ecom%3Fq%3Djump\",\"suffix\":{\"option\":\"UNGUESSABLE\"}}"
"https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=REPLACE_THIS_WITH_YOUR_API_KEY”
Let me know how it worked.
If this line was able to create short link, than error in iOS code.
curl -X POST --dump-header - -H "X-Ios-Bundle-Identifier: com.debugbundlefromanotherfirebaseproject.debug" -H "Accept: application/json" -H "Content-Type: application/json" -d "{\"longDynamicLink\":\"https:\/\/RELEASE_DOMAIN.app.goo.gl\/?link=https%3A%2F%2Fwww%2Egoogle%2Ecom%3Fq%3Djump\",\"suffix\":{\"option\":\"UNGUESSABLE\"}}" "https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=API_KEY_RELEASE"
{
"shortLink": "https://RELEASE_DOMAIN.app.goo.gl/EDKuPWwaXrFzfs4S2",
"warning": [
{
"warningCode": "UNRECOGNIZED_PARAM",
"warningMessage": "Android app 'android.com.releaseandroidid' lacks SHA256. AppLinks is not enabled for the app. [https://firebase.google.com/docs/dynamic-links/debug#android-sha256-absent]"
},
{
"warningCode": "UNRECOGNIZED_PARAM",
"warningMessage": "Android app 'android.com.debugeandroididfromanotherfirebaseproject' lacks SHA256. AppLinks is not enabled for the app. [https://firebase.google.com/docs/dynamic-links/debug#android-sha256-absent]"
}
],
"previewLink": "https://RELEASE_DOMAIN.app.goo.gl/EDKuPWwaXrFzfs4S2?d=1"
}
I think that could be problem in Firebase. Because for release project domain POST work although request have mistake bundle id, additional in result warnings contain one warning with android ID from another Firebase project. I am waiting for response from firebase. Example above.

Update a page in Confluence using REST API

This is what I've currently got and it creates a new Confluence page. It doesn't update it. Also it posts it in the root space, TST, but I want it to be in TST/space1/subsection2/updateThisPage.
curl -v -u admin:admin -X POST -H Content-Type: application/json -d "{\"id\":\"123456\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"TST\",\"title\":\"updateThisPage\"},\"body\":{\"storage\":{\"value\":\"<p>This is the updated text for the new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":3}}" http://localhost:8090/rest/api/content?spaceKey=TST&title=updateThisPage
This is the error message I get
{"statusCode":400,"message":"A page with this title already exists: A page already exists with the title new page in the space with key TST"}
Would it be a permissions error? I know I do not have access to delete.
Use request /rest/api/content/{id}.
This worked for me.
curl -u admin:admin -X PUT -H "Content-Type: application/json" -d "{\"id\":\"26738701\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"RO\"},\"body\":{\"storage\":{\"value\":\"<p>UPDATE This is a new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":2}}" http://localost:10080/rest/api/content/26738701
JSON Payload:
{
"id":"26738701",
"type":"page",
"title":"new page",
"space":{
"key":"RO"
},
"body":{
"storage":{
"value":"<p>UPDATE This is a new page</p>",
"representation":"storage"
}
},
"version":{
"number":2
}
}
Don't forget to use:
content ID in data part
version number in data part
PUT request
content ID in request
Try to use PUT instead of POST.
curl -v -u admin:admin -X PUT -H Content-Type: application/json -d "{\"id\":\"123456\",\"type\":\"page\",\"title\":\"new page\",\"space\":{\"key\":\"TST\",\"title\":\"updateThisPage\"},\"body\":{\"storage\":{\"value\":\"<p>This is the updated text for the new page</p>\",\"representation\":\"storage\"}},\"version\":{\"number\":3}}" http://localhost:8090/rest/api/content?spaceKey=TST&title=updateThisPage
If anyone is looking for javascript solution, here is my answer to another question like that
Unexpected grunt-http error when posting to Atlassian Confluence api
And here you can find working code i've developed on confluence hackathon
https://github.com/devex-web-frontend/dxWebPlugins/blob/master/src/confluence/helpers/buffer.js

Resources