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

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": ""
}
}
]
}'

Related

Dart : At the end of the tutorial, I don't know how to check that the app is working

https://dartfrog.vgv.dev/docs/tutorials/todos#summary
I got to this section, but I don't know how to get it to work at the end, so I can't get it to work.
in my browser
http://localhost:8080/todos
When I access the above url, [] is displayed, so I think it's working.
# Update a specific todo by id
curl --request PUT \
--url http://localhost:8080/todos/<id> \
--header 'Content-Type: application/json' \
--data '{
"title": "Take out trash!",
"isCompleted": true
}'
How can I check that the above part works?
The line you see there is a command you are supposed to run on your commandline.
If you use a newer version of windows you probably have curl already, if not, see How do I install and use cURL on Windows?
So you open your command prompt and enter
curl --request PUT --url http://localhost:8080/todos/<id> --header 'Content-Type: application/json' --data '{ "title": "Take out trash!", "isCompleted": true }'
where I guess the <id> part needs to be an id. So for example 1.
Please note that that is a tutorial for a backend in Dart. They are not commonly called an app. If you are looking to build a nice app for your device or webbrowser, with ui controls like input boxes and buttons, you are reading the wrong tutorial.

Bitbucket repository creations by api

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.

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

JIRA: Rest API Authentication for CURL command

I'm looking to make a POST request to create an issue on my JIRA server. I was able to make a successful request using postman and basic authentication, but I would like to use the bearer method.
Here is my curl command:
curl --request POST--header 'Authorization: Bearer <token>'--header 'Accept: application/json'--header 'Content-Type: application/json'--data '{ "fields": { "project": {"key": "key"}, "summary": "Bug notification", "description": "THis is a test notification from cmd", "issuetype": {"name": "Bug"},"components": [{ "id": "0000"}], "priority": { "id": "2"}}}'--url 'https://server.atlassian.net/rest/api/2/issue'
Can someone please guide me on how to get the token, I have combed through a lot of documentation and nothing seemed to fit the bill?
you need to go to the api tokens page and create one from there
you need to create a token by following this instruction https://support.atlassian.com/atlassian-account/docs/manage-api-tokens-for-your-atlassian-account/
After the token is generated, you need to copy it and put some syntax below.
Get the issue example.
curl --request GET \
--url 'https://your-domain.atlassian.net/rest/api/2/issue/{issueIdOrKey}' \
--user 'email#example.com:<api_token>' \
--header 'Accept: application/json'

BigCommerce webhooks listener in rails

I'm following the instructions here http://developer.bigcommerce.com/api/webhooks/quickstart to set up webhooks to initiate some third-party order processing. We've been doing this on an hourly batch, real-time webhook triggers will save us a lot of lag time.
I think I've set up the webhook broadcaster, but can't see any evidence that it's being fired- I've created a bunch of new orders and nothing reaches the rails server.
How can I tell if BigCommerce is firing events when / where I expect?
Generated the access token for the given app/user/domain:
curl -XPOST -d '{
"client_id":"[BigCommerceAppClientId]",
"client_secret":"[BigCommerceAppSecret]",
"user":"admin",
"token":"[adminAPIToken]",
"store_domain":"https://[myStore].mybigcommerce.com"
}' https://hooks-beta.bigcommerce.com/token
yields ===>
{
"access_token":"[webHooksAccessToken]",
"producer":"store/[myStoreKey]"
}
Subscribed to webhooks for store/events/listener:
curl -XPOST -d '{
"producer":"store/[myStoreKey]",
"scope":"store/order/created",
"deliverymethod":"HTTP_POST",
"destination":{"url":"http://[myPublicRailsServer]/hooks"}
}' -H 'X-Auth-Client: [BigCommerceAppClientId]' -H 'X-Auth-Token:[X-Auth-Token]' https://hooks-beta.bigcommerce.com
yields ===>
{
"client_id":"[webHooksAccessToken]",
"created_at":"2013-06-27T19:57:38+00:00",
"deliverymethod":"HTTP_POST","destination":{"url":"http://[myPublicRailsServer]/hooks"},
"id":651,
"producer":"store/[myStoreKey]",
"scope":"store/order/created",
"updated_at":"2013-06-27T19:57:38+00:00"
}
I lied. The problem was apparently trying to use https instead of http. Everything works as expected.
Furthermore- BigCommerce provides a hook to check the active clients for a given application:
curl -XGET -H
'X-Auth-Client: [BigCommerceAppClientId]' -H
'X-Auth-Token: [BigCommerceAppSecret]'
https://hooks-beta.bigcommerce.com/producer/store/[myStoreKey]

Resources