Posting to orion gets me to "Attribute must be a JSON object" - fiware-orion

I am sending this to Orion:
curl --location --request POST 'http://xx.xx.xx.xx:1026/ngsi-ld/v1/entities/' \
--header 'link: <https://smartdatamodels.org/context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
--header 'Content-Type: application/json' \
--data-raw '{
"id": "urn:ngsi-ld:Device:01",
"type": "Device",
"description": "L9A",
"category": {
"value": ["sensor"]
},
"serialNumber": {
"value": "38479144"
},
"controlledProperty": {
"value": ["Water Supply"]
},
"owner": {
"value": ["Me"]
},
"location": {
"type": "Point",
"coordinates": [20.200416, 30.261837]
}
}'
and I get this:
Error 400: Bad Request
{
"type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData",
"title": "Attribute must be a JSON object",
"detail": "description"
}
I validated by json object and it passes. What am I doing wrong?

Look a little closer at your error message, especially:
detail": "description"
That's the name of the attribute that is not a JSON object:
"description": "L9A"
If you change it to:
"description": {
"type": "Property",
"value": "L9A"
}
that part should be OK.
But, the type member seems to be missing for all your attributes.
you'll need to add "type": "Property" to all of them, except "location" that's a GeoProperty:
"location": {
"type": "GeoProperty",
"value": {
"type": "Point",
"coordinates": [20.200416, 30.261837]
}
}
Perhaps spend some time reading the NGSI-LD specification?
https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.04.02_60/gs_CIM009v010402p.pdf

Related

PayPal v2 Onboarding error with multiple products

I'm trying integrate PayPal V2 Onboarding in sandbox.
My call is :
curl -v -X POST https://api-m.sandbox.paypal.com/v2/customer/partner-referrals \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <My-Access-Token> " \
-d '{
"tracking_id": "795_123",
"operations": [
{
"operation": "API_INTEGRATION",
"api_integration_preference": {
"rest_api_integration": {
"integration_method": "PAYPAL",
"integration_type": "THIRD_PARTY",
"third_party_details": {
"features": [
"PAYMENT",
"REFUND"
]
}
}
}
}
],
"products": [
"EXPRESS_CHECKOUT",
"PPPLUS"
],
"legal_consents": [
{
"type": "SHARE_DATA_CONSENT",
"granted": true
}
]
}'
And the response is :
{
"name": "INVALID_REQUEST",
"message": "Request is not well-formed, syntactically incorrect, or violates schema.",
"debug_id": "266c1b0e09a8f",
"information_link": "",
"details": [{
"issue": "INVALID_ARRAY_LENGTH",
"description": "The number of items in an array should not be more than 1",
"field": "/products",
"location": "body"
}],
"links": []
}
Has anyone come up to this error message for "products" array, or is this a PayPal v2 Onboarding bug?

CURL request to kafka-rest

I have executed HTTP POST on kafka-rest using curl call. one request is successful but another request (with different json) is returned 422 error ({"error_code":422,"message":"Unrecognized field: receiver"}).
Working request
curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json" -H "Accept: application/vnd.kafka.v2+json" --data '{"records":[{"value":{"foo":"bar"}}]}' "http://localhost:8082/topics/jsontest"
Outout
{"offsets":[{"partition":0,"offset":0,"error_code":null,"error":null}],"key_schema_id":null,"value_schema_id":null}
Not working request
curl -X POST -H "Content-Type: application/vnd.kafka.json.v2+json" -H "Accept: application/vnd.kafka.v2+json" --data #alert-request.json "http://localhost:8082/topics/jsontest"
Output
{"error_code":422,"message":"Unrecognized field: receiver"}
alert-request.json
{
"receiver": "email-logs",
"status": "firing",
"alerts": [
{
"status": "firing",
"labels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"annotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"startsAt": "2020-04-30T08:03:17.309164516Z",
"endsAt": "0001-01-01T00:00:00Z",
"generatorURL": "http://0ab6d9955c65:9090/graph?g0.expr=60+%3E+job%3Anode_cpu_seconds%3Ausage+%3E+20\u0026g0.tab=1",
"fingerprint": "9c558a8c20c2ba08"
}
],
"groupLabels": {
"alertname": "CPUUsageAbove20%",
"team": "raptors"
},
"commonLabels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"commonAnnotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"externalURL": "http://5493399b56dc:9093",
"version": "4",
"groupKey": "{}/{team=~\"^(?:(raptors|leafs))$\"}:{alertname=\"CPUUsageAbove20%\", team=\"raptors\"}"
}
I need to write above json to kafka using kafka-rest, and i use curl call to perform HTTP post on kafka-rest but it's returning error. how to successfully write to kafka using kafka-rest (using curl)?.
The error code in the response as "error_code":422 means that the request payload is incorrect.
According the API spec of kafka-rest, the one of the valid request payload structure is
{
"records": [
{
"key": "recordKey",
"value": "recordValue"
}
]
}
So your alert-request.json file should be modified with the contents under the value field inside records
{
"records": [
{
"key": "recordKey",
"value": {
"receiver": "email-logs",
"status": "firing",
"alerts": [
{
"status": "firing",
"labels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"annotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"startsAt": "2020-04-30T08:03:17.309164516Z",
"endsAt": "0001-01-01T00:00:00Z",
"generatorURL": "http://0ab6d9955c65:9090/graph?g0.expr=60+%3E+job%3Anode_cpu_seconds%3Ausage+%3E+20\u0026g0.tab=1",
"fingerprint": "9c558a8c20c2ba08"
}
],
"groupLabels": {
"alertname": "CPUUsageAbove20%",
"team": "raptors"
},
"commonLabels": {
"alertname": "CPUUsageAbove20%",
"instance": "node-exporter:9100",
"job": "node-exporter",
"monitor": "my-project",
"severity": "warn",
"team": "raptors"
},
"commonAnnotations": {
"dashboard": "www.prometheus.io",
"description": "CPU usage on node-exporter:9100 has reached 60"
},
"externalURL": "http://5493399b56dc:9093",
"version": "4",
"groupKey": "{}/{team=~\"^(?:(raptors|leafs))$\"}:{alertname=\"CPUUsageAbove20%\", team=\"raptors\"}"
}
}
]
}
Do note that the key field is optional and you can provide any unique key that suits your use-case.

How to make a post API for mongodb with loopback

I am newbie with mongodb and loopback. I want to send and save data from my app to database. how can I do that?
Update
shops model:
{
"shopname": "string",
"tel": "string",
"latlng": "string",
"address": "string",
"id": "string",
"personId": "string"
}
CURL:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ \
"shopname": "spring", \
"tel": "12345678", \
"latlng": "52.1106986,21.7768998", \
"address": "05-319 Skwarne, Poland" \
}' 'http://localhost:3000/api/shops'
Now what should I write in shops.js to give an api for using in app to send data to database ?
'use strict';
module.exports = function(Shops) {
};
you should have provided more info about the steps you have already done.
let me begin with the first step:
download and install mongodb on your server: link
after running mongodb, add your desired database info to datasources.json file. e.g.
{
"db": {
"name": "db",
"connector": "memory"
},
"shopDB": {
"host": "localhost",
"port": 27017,
"url": "mongodb://localhost:27017/shopDB",
"database": "shopDB",
"password": "",
"name": "shopDB",
"user": "",
"connector": "mongodb"
}
}
add loopback-connector-mongodb to your project via npm.
now define your model(you can utilize loopback's user friendly command line interface to do so. call command "slc loopback:model" in your projects root folder)
after you finish the step 4, loopback will create 2files for you: shop.js and shop.json => these files are located in your projectFolder/common/models/ directory. note that it's a good practice to follow the loopback's convention in naming models and name your model in singular form(shop). (it uses the plural forms of the model names in other parts of the project). your shop.json should look like the below code:
{
"name": "shop",
"plural": "shops",
"base": "PersistedModel",
"idInjection": true,
"options": {
"validateUpsert": true
},
"properties": {
"shopname": {
"type": "string",
"required": true
},
"tel": {
"type": "string",
"required": true
},
"latlng": {
"type": "string",
"required": true
},
"address": {
"type": "string"
},
"personId": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {},
"acls": [],
"methods": {}
}
now you can post your shop json to http://localhost:3000/api/shops/ . note that our shop model inherits from PersistedModel base model and has some built-in functions to do crud operations. and if you want just create some shop instances in your db, you won't need to add anything to your shop.js file!

List all entities resources functionality seems to be failing in API v2

If we perform <cb_url>:<cb_port>/v2/entitites/EntityId/attrs request as described in http://fiware.github.io/context.Orion/api/v2/cookbook/, we get a "service not found" error.
For this test we used the Docker image from https://hub.docker.com/r/fiware/orion/
Version information about the build:
{
"orion" : {
"version" : "1.0.0-next",
"uptime" : "1 d, 3 h, 48 m, 6 s",
"git_hash" : "b6752828f37711bed6e1ff670207d6b984bc9570",
"compile_time" : "Tue Apr 5 18:25:46 UTC 2016",
"compiled_by" : "root",
"compiled_in" : "838a42ae8431"
}
}
Steps to replicate:
Create an entity:
(curl -X POST <orion_host>:1026/v2/Entities?options=keyValues -s -S --header 'Content-Type: application/json' \
--header 'Accept: application/json' -d #- | python -mjson.tool) <<EOF
{
"type": "Review",
"id": "review-36",
"author": "AuthorId",
"itemReviewed": "LeBistro",
"reviewBody": "Body of the review",
"ratingValue": 4
}
EOF
Try to retrieve its attributes with:
curl <orion_host>:1026/v2/Entities/review-36/attrs
or
curl <orion_host>:1026/v2/Entities/review-36/attrs?options=keyValues
In both cases we get:
{
"error": "BadRequest",
"description": "service not found"
}
If we perform:
curl <orion_host>:1026/v2/Entities/review-36
We get:
{
"id": "review-36",
"type": "Review",
"author":
{
"type": "none",
"value": "AuthorId",
"metadata": {}
},
"itemReviewed":
{
"type": "none",
"value": "LeBistro",
"metadata": {}
},
"ratingValue":
{
"type": "none",
"value": 4,
"metadata": {}
},
"reviewBody":
{
"type": "none",
"value": "Body of the review",
"metadata": {}
}
}
Or if we perform :
curl <orion_host>:1026/v2/Entities/review-36?options=keyValues
We get:
{
"id": "review-36",
"type": "Review",
"author": "AuthorId",
"itemReviewed": "LeBistro",
"ratingValue": 4,
"reviewBody": "Body of the review"
}
I recommend to use reference instead of cookbook.
And in this case your problem is that the url /v2/Entities/review-36/attrs is malformed.
Possible Requests:
GET /v2/entities --> return all entities
GET /v2/entities/<id> --> return an entity associated to this id
GET /v2/entities/<id>/attrs/<attr_name> --> return only an attribute in the entity associated to this id
GET /v2/entities/<id>/attrs/<attr_name>/value --> return only the attribute value associated to an attribute into an entity with this id
I think the /attrs is not a "malformed URL" it is something not already implemented ...

Orion doesn't notify Cygnus

I followed the official documentation about cygnus and orion. All generic enablers are deployed correctly, without errors in their log files. But something strange happens, Orion never notifies Cygnus.
To test this mechanism I followed the example with Car entity provided in the official documentation.
My entity creation bash script:
(curl $1:1026/v1/updateContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d #- | python -mjson.tool) <<EOF
{
"contextElements": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1",
"attributes": [
{
"name": "speed",
"type": "integer",
"value": "75"
},
{
"name": "fuel",
"type": "float",
"value": "12.5"
}
]
}
],
"updateAction": "APPEND"
}
EOF
My entity subscription bash script:
(curl $1:1026/v1/subscribeContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Fiware-Service: vehicles' --header 'Fiware-ServicePath: /4wheels' -d #- | python -mjson.tool) <<EOF
{
"entities": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1"
}
],
"attributes": [
"speed",
"oil_level"
],
"reference": "http://$2:5050/notify",
"duration": "P1M",
"notifyConditions": [
{
"type": "ONCHANGE",
"condValues": [
"speed"
]
}
],
"throttling": "PT1S"
}
EOF
My entity update bash script:
(curl $1:1026/v1/updateContext -s -S --header 'Content-Type: application/json' --header 'Accept: application/json' -d #- | python -mjson.tool) <<EOF
{
"contextElements": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1",
"attributes": [
{
"name": "speed",
"type": "integer",
"value": $2
}
]
}
],
"updateAction": "UPDATE"
}
EOF
Note: Orion responds to all requests.
After executing these scripts, cygnus must receive reported information from orion and save it in the database, but nothing happens.
Neither in /var/log/cygnus/cygnus.log file or in /var/log/contextBroker/contextBroker.log file are reported any information about orion notification.
Note: If I use the notify.sh script provided in the official documentation, Cygnus works well and saves all data in the database.
Note: I read in other questions problems about open ports but those don't apply to mine.
EDIT 1
After I subscribe the orion, the response is:
{
"subscribeResponse": {
"duration": "P1M",
"subscriptionId": "563e12b4f4d8334d599753e0",
"throttling": "PT1S"
}
}
And when I update anentity, orion returns it:
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "speed",
"type": "integer",
"value": ""
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
To GET entity from orion I used the following script:
(curl $1:1026/v1/queryContext -s -S --header 'Content-Type: application/json' \
--header 'Accept: application/json' -d #- | python -mjson.tool) <<EOF
{
"entities": [
{
"type": "Car",
"isPattern": "false",
"id": "Car1"
}
]
}
EOF
Response:
{
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "fuel",
"type": "float",
"value": "12.5"
},
{
"name": "speed",
"type": "integer",
"value": "123"
}
],
"id": "Car1",
"isPattern": "false",
"type": "Car"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
Note The speed value was updated with success.
Taking into account the Fiware-Service and Fiware-ServicePath headers in subscription request, it has been performeed in the "/4wheels" service path of the service "vehicles". However, entity creation request doesn't use such headers, so it is created in the default service path ("/") of the default service. Thus, the subscription is not "covering" the entity, so updates in the entity are not triggering notifications.
One solution to the problem would be to create the entity in the same service and service path of the subscription, i.e. "/4wheels" service path of the service "vehicles".
Please, check Orion official documentation about service and service path concepts.