How to include fiware-service and fiware-servicePath headers in an Orion Context Broker registration to a Context Provider? - fiware-orion

We are researching about the Orion Context Broker technology using local Docker containers and trying to integrate the local Context Broker with an external Context Provider.
Specifically, we are trying to retrieve data from this Context provider:
https://streams.lab.fiware.org/v2/entities?type=AirQualityObserved&options=keyValues
Using the headers:
fiware-service: environment
fiware-servicePath: /Madrid
Concretely, our objective is to achieve a registration from our Context Broker to this node of the provider, in order to get some attributes that we don't have in local (in that example, the attribute is called "NO").
The request we are sending for the registration is the following one:
curl -iX POST \
'http://localhost:1026/v2/registrations' \
-H 'Content-Type: application/json' \
-d '{
"description": "Air Quality Madrid",
"dataProvided": {
"entities": [
{
"id": "Madrid-AirQualityObserved-28079059-latest",
"type": "AirQualityObserved"
}
],
"attrs": [
"NO"
]
},
"provider": {
"http": {
"url": "https://streams.lab.fiware.org"
}
}
}'
Additionally, we have created a local entity with the same id as in the request: Madrid-AirQualityObserved-28079059-latest
After that information, the question is:
Is it possible to include the specific fiware-service and fiware-servicePath headers into the registration request? What is the way to include them?
Thanks in advance.
EDIT:
I've been doing more tests with the following commands:
For registering to the context provider, using the specific headers for the desired service. For now, the local entity is not created in the local context broker.
curl -iX POST \
'http://localhost:1026/v2/registrations' \
-H 'Content-Type: application/json' \
-H 'fiware-service: environment' \
-H 'fiware-servicepath: /Madrid' \
-d '{
"description": "Air Quality Madrid",
"dataProvided": {
"entities": [
{
"id": "Madrid-AirQualityObserved-28079059-latest",
"type": "AirQualityObserved"
}
],
"attrs": [
"NO"
]
},
"provider": {
"http": {
"url": "https://streams.lab.fiware.org"
}
}
}'
Then, I've check if the registration has been correctly registered:
curl -X GET http://localhost:1026/v2/registrations \
-H 'fiware-service: environment'
-H 'fiware-servicepath: /Madrid'
Finally, I've tried to retrieve the entity from the provider:
curl -X GET http://localhost:1026/v2/entities/Madrid-AirQualityObserved-28079059-latest \
-H 'fiware-service: environment' \
-H 'fiware-servicepath: /Madrid'
But the response indicates that there is not any entity for that request. Because of that, I've created the entity in the local context broker, excluding the field that I'm trying to obtain from the provider "NO".
curl -iX POST \
'http://localhost:1026/v2/entities' \
-H 'Content-Type: application/json' \
-H 'fiware-service: environment' \
-H 'fiware-servicepath: /Madrid' \
-d '
{
"id": "Madrid-AirQualityObserved-28079059-latest",
"type": "AirQualityObserved"
}'
However, if I consult the entity with the ID Madrid-AirQualityObserved-28079059-latest, I'm receiving the local data, and the field "NO" is not being retrieved from the provider. That is the response (missing the NO field):
{
"id": "Madrid-AirQualityObserved-28079059-latest",
"type": "AirQualityObserved"
}
What I am doing wrong?

Yes, it's possible.
They are included as regular headers. For instance, if you are using curl, it would be something like -H 'fiware-service: environment' -H 'fiware-servicepath: /Madrid'.
EDIT:
Looking to the query request you are using:
curl -X GET http://localhost:1026/v2/entities/Madrid-AirQualityObserved-28079059-latest \
-H 'fiware-service: environment' \
-H 'fiware-servicepath: /Madrid'
I see are not incluing the entity type in the query, contrary to the recomendation in the context providers and request forwarding documentantation:
On forwarding, any type of entity in the NGSIv2 update/query matches registrations without entity type. However, the opposite doesn't work, so if you have registrations with types, then you must use ?type in NGSIv2 update/query in order to obtain a match. Otherwise you may encounter problems, like the one described in this post at StackOverflow.
So maybe you should use:
curl -X GET http://localhost:1026/v2/entities/Madrid-AirQualityObserved-28079059-latest?type=AirQualityObserved \
-H 'fiware-service: environment' \
-H 'fiware-servicepath: /Madrid'

Related

How to set the secret in Bitbucket Server Create Webhook API call

I have crafted a curl which looks something like this. It successfully creates a webhook in BitBucket Server, however, it does not set the 'secret' value, and because of this when the webhook is triggered it fails with a 'missing signature in header'.
If I manually set the secret value, it will then work.
I have looked through Bitbucket Server documentation for 'Create webhook'
and do not see anything related.
Link for reference:
https://developer.atlassian.com/server/bitbucket/rest/v804/api-group-repository/#api-api-latest-projects-projectkey-repos-repositoryslug-webhooks-post
url --request POST \
--url 'https://git.example.org/rest/api/latest/projects/DP/repos/demo/webhooks' \
--header 'Authorization: Bearer xxx' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"events": [
"repo:refs_changed"
],
"active": true,
"statistics": {},
"configuration": {},
"url": "http://example.org/push",
"name": "Argo Events"
}'
After opening web tools and manually creating the webhook in the BitBucket website, we inspected the network tab and found that it was stored in the configuration object.
Example curl below.
curl --request POST \
--url 'https://example.org/webhooks' \
--header 'Authorization: Bearer xxx' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"events": [
"repo:refs_changed"
],
"active": true,
"statistics": {},
"configuration": {"createdBy": "bitbucket","secret": "password"},
"url": "http://example.org/push",
"name": "Argo Events"
}'

How to Send a cURL style request in Swift

I'm trying to communicate with an SMTP API from my IOS application. The API uses HTTPS requests, however, I'm unsure how to make one within Swift. The application exemplifies the following cURL request as a way of communicating with the API:
curl --request POST \
--url https://api.sendinblue.com/v3/smtp/email \
--header 'accept: application/json' \
--header 'api-key:YOUR_API_KEY' \
--header 'content-type: application/json' \
--data '{
"sender":{
"name":"Sender Alex",
"email":"senderalex#example.com"
},
"to":[
{
"email":"testmail#example.com",
"name":"John Doe"
}
],
"subject":"Hello world",
"htmlContent":"<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Sendinblue.</p></body></html>"
}'
How can I make this request from my code project?
Any help would be greatly appreciated!

Creating merchant application using Identity API for Paypal

I am trying to create an application for merchants using the below API.
https://developer.paypal.com/docs/api/identity/v1
Not able to create that passed the required parameters. I have payer_id id which I am getting in the response of /v1/identity/oauth2/userinfo. I get that special permissions from Paypal.
Here is my request body
curl -v -X POST https://api.paypal.com/v1/identity/applications \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ------------------------" \
-d '{
"application_type": "not cleared what need to add here",
"redirect_uris": [
"return url"
],
"client_name": "Avtar Singh",
"contacts": [
"-------"
],
"payer_id": "-------------",
"migrated_app": "not cleared what need to add here"
}'

fiware-orion notification failure with https

I have a problem with my Fiware-Orion (2.1.0) notifications with Quantum-Leap for managing time-series datas (related to that component quantumleap ).
Both are within Docker containers and using HTTPS.
In orion I create the subscription for Quantum-Leap. It works.
And when I create or update an entity, Orion send me an 200 OK response and the notification never reach Quantum-Leap.
I have nothing in logs.
When I make a request directly to an endpoint using Curl or Postman, the request works. Requests using Orion always fail.
Here is the curl used by Postman to QuantmLeap that works.
curl -X POST \
https://ql1-dev.mydomain.com/v2/notify \
-H 'Accept: application/json' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Fiware-Service: svctestnca' \
-H 'Fiware-ServicePath: /svcpath/testnca' \
-H 'Host: ql1-dev.intranice.ville-nice.fr' \
-H 'Ngsiv2-AttrsFormat: normalized' \
-H 'Postman-Token: 76255023-47e3-44c5-8abf-d184a1dd77f0,adaa68e0-abf4-4fea-855d-39c3469ba1d4' \
-H 'User-Agent: PostmanRuntime/7.11.0' \
-H 'accept-encoding: gzip, deflate' \
-H 'cache-control: no-cache' \
-H 'content-length: 279' \
-d '{
"subscriptionId": "5c62b47f132e5369012c4726",
"data": [
{
"id": "Testnca:testnca1",
"type": "Testnca",
"dateObserved": {
"type": "DateTime",
"value": "2019-02-04T16:19:22.00Z"
},
"mesure": {
"type": "Number",
"value": 2.0
}
}
]
}'
Thanks for help and advices
I tried to use HAProxy like in this Stack-Overfow question and it solves my problem.
Orion always add the port number to my request and I missed that element.
Thank you all and especially StephaneRouxNCA

How to send a curl request to timekit.io API

I am trying to follow the documentation from timekit.io. I am attempting to do something as simple as send a curl request to do basic authentication as seen in this section of the docs. I have replaced the Timekit-App:name-of-app with the name of my app which I found in the app-settings of my timekit account. I also replaced the email & password with the one's I use to login into my account.
I simply copied and pasted the curl command as is into my terminal and I get a response that says {"error":"Content-type should be json!"} I am not sure if I am not supposed to copy and paste it as is, or what I may be doing wrong, but my understanding is I am supposed to get a json response with a email and a api token among some other data.
Here is my curl command.
curl -X POST \
-H 'Timekit-App: jl-fit' \
-d '{
"email": "email#email.com",
"password": "password"
}' \
https://api.timekit.io/v2/auth
Looks like you have discovered a bug in their docs/examples.
The API you're connecting to expects JSON content type, but curl by default (for POSTing data) uses application/x-www-form-urlencoded. You can fix it by adding the header field explicitly with: -H 'Content-Type: application/json'.
Also, when you use the -d/--data option, method defaults to POST, so it doesn't have to be specified explicitly.
All put together, this should work:
curl \
-H 'Content-Type: application/json' \
-H 'Timekit-App: jl-fit' \
-d '{"email": "email#email.com", "password": "password"}' \
"https://api.timekit.io/v2/auth"
When having multiple arguments, it can be convenient to keep them in an array (no need to escape newlines). For example:
args=(
-H 'Content-Type: application/json'
-H 'Timekit-App: jl-fit'
-d '{"email": "email#email.com", "password": "password"}'
"https://api.timekit.io/v2/auth"
)
curl "${args[#]}"