FIWARE Orion: use query string in subscription payload - fiware-orion

Currently the '=' sign is forbidden in Orion:
http://fiware-orion.readthedocs.io/en/1.5.0/user/forbidden_characters/index.html
But this prevents to make a subscription with a query string:
$ (curl broker.waziup.io/v1/subscribeContext -s -S --header 'Content-Type: application/json' \
--header 'Accept: application/json' --header 'Fiware-Service:waziup' --header 'Fiware-ServicePath:/TEST' -d #- | python -mjson.tool) <<EOF
{
"entities": [
{
"type": "SensingDevice",
"isPattern": "false",
"id": "Sensor1"
}
],
"attributes": [
"temperature"
],
"reference": "http://localhost/v1/sms/send?contact=0039&msg=Sensor1",
"duration": "P1M",
"notifyConditions": [
{
"type": "ONCHANGE",
"condValues": [
"temperature"
]
}
],
"throttling": "PT1S"
}
EOF
Results in:
{
"subscribeError": {
"errorCode": {
"code": "400",
"details": "Illegal value for JSON field",
"reasonPhrase": "Bad Request"
}
}
}
The query string is used to pass parameters to the callback server (I don't see other ways to do it).
Any way around this?

There is a way of setting query parameters in the notification URL, based in custom notifications in NGSIv2. Have a look to "Custom Notifications" section in the NGSIv2 specification.
The subscription you are doing would be something like this:
POST /v2/subscriptions
...
{
"subject": {
"entities": [
{
"id": "Sensor1",
"type": "SensingDevice"
}
],
"condition": {
"attrs": [ "temperature" ]
}
},
"notification": {
"httpCustom": {
"url": "http://localhost/v1/sms/send",
"qs": {
"contact": "0039",
"msg": "Sensor1"
}
},
"attrs": [ "temperature"]
},
"expires": "2016-05-07T18:30:00.00Z",
"throttling": 1
}
Note that you could even generalize the subscriptions for all your sensors using templates, in the following way:
POST /v2/subscriptions
...
{
"subject": {
"entities": [
{
"idPattern": "Sensor.*",
"type": "SensingDevice"
}
],
"condition": {
"attrs": [ "temperature" ]
}
},
"notification": {
"httpCustom": {
"url": "http://localhost/v1/sms/send",
"qs": {
"contact": "0039",
"msg": "${id}"
}
},
"attrs": [ "temperature"]
},
"expires": "2016-05-07T18:30:00.00Z",
"throttling": 1
}

Related

How to pass paramters to argo workflow api

I am running my workflow through argo workflow api ,and I am not able to pass dynamic input paramters
curl -k --request POST \
--url https://localhost:2746/api/v1/workflows/argo \
--header 'content-type: application/json' \
--data '{
"namespace": "argo",
"serverDryRun": false,
"workflow": {
"metadata": {
"generateName": "hello-world-",
"namespace": "argo",
"labels": {
"workflows.argoproj.io/completed": "false"
}
},
"spec": {
"templates": [
{
"name": "whalesay",
"arguments": {},
"inputs": {
"parameters":{
"name":"sh#yahoo.com"
}
},
"outputs": {},
"metadata": {},
"container": {
"name": "",
"image": "gandalf/patientreg",
"command": [
"./app"
],
"args": [
""
],
"resources": {}
}
}
],
"entrypoint": "whalesay",
"arguments": {}
}
}
}'
I am getting this error while running the workflow
{"code":3,"message":"json: cannot unmarshal object into Go struct
field Inputs.workflow.spec.templates.inputs.parameters of type
[]v1alpha1.Parameter"}%
I want to pass dynamic email through api and receive if as command line arguments in my app such that I can run my workflow .
How to achieve that ?
You can pass parameters to the workflow which instead can be sent to any step inside the workflow. The parameter should have a name. In your example you are only passing the value directly to the step.
Here is an example payload.
{
"workflow": {
"metadata": {
"name": "awesome-dragon",
"namespace": "argo",
"labels": {
"example": "true"
}
},
"spec": {
"arguments": {
"parameters": [
{
"name": "workflow-arg",
"value": "mail.from#outside.code"
}
]
},
"entrypoint": "argosay",
"templates": [
{
"name": "argosay",
"inputs": {
"parameters": [
{
"name": "step-level-arg",
"value": "{{workflow.parameters.workflow-arg}}"
}
]
},
"container": {
"name": "main",
"image": "argoproj/argosay:v2",
"command": [
"/argosay"
],
"args": [
"echo",
"{{inputs.parameters.step-level-arg}}"
]
}
}
],
"ttlStrategy": {
"secondsAfterCompletion": 300
},
"podGC": {
"strategy": "OnPodCompletion"
}
}
}
}
Note that an named argument is passed from outside to the argo workflow. The same workflow argument can be utilized any template inside.

Powershell Invoke-RestMethod in LogicApps

For this line of code in Powershell I used an HTTP connector in Logic Apps using Joey Cai's advice.
$body_login = #{"method"="login";"username"="qq";"password"="qqq"} | ConvertTo-Json
Now, I have this line of code in Powershell. How do I do the equivalent in LogicApps?
$Conn = Invoke-RestMethod -Method Post $uri_login -Headers $header -Body $body_login
Do I use the same HTTP connector or do I need something else? It's the Invoke-RestMethod syntax that I'm unsure of in Logic Apps.
I will need the output in JSON format, so I can parse it.
Thanks for the first answer. I need to know what to put in the uri, header and body. Here is the rest of the code which I should have provided before.
$baseuri = "https://test"
$header = #{
"Accept" = "text/json"
"Content-Type" = "text/json"
}
$G_header = #{"Accept" = "text/json"}
Write-Output "Login ..."
$uri_login = $baseuri + "SPDEDJSONSERVICE.LOGIN"
$body_login = #{"method"="login";"username"="qqq";"password"="qqq"} | ConvertTo-Json
$Conn = Invoke-RestMethod -Method Post $uri_login -Headers $header -Body $body_login
$SessionID = $conn.sessionID</code>
How do I do the equivalent in LogicApps?
As I have provided before, use HTTP connector.
I will need the output in JSON format, so I can parse it.
You could use Compose to work with data in JSON format.
1.Add Headers/Body which you want into Compose.
2.Add Outputs into Parse JSON. Copy the HTTP response Headers/Body info, and click use sample payload to generate schema, then parse Headers in it.
3.Use Initialize variable to get info what you want such as Date.
The result:
With Azure Logic Apps and the built-in HTTP action, you can create automated tasks and workflows that regularly send requests to any HTTP or HTTPS endpoint.
Sign in to the Azure portal. Open your logic app in Logic App Designer.
Under the step where you want to add the HTTP action, select New step.
To add an action between steps, move your pointer over the arrow between steps. Select the plus sign (+) that appears, and then select Add an action.
Under Choose an action, in the search box, enter "http" as your filter. From the Actions list, select the HTTP action.
Select HTTP action
For your scenarion you can use Basic Authentication.
This seems to work, but I could not have done it without Joey
<code>
{
"definition": {
"$schema":
"https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-
01/workflowdefinition.json#",
"actions": {
"HTTP_2": {
"inputs": {
"body": {
"FORMAT": "payload",
"FROM": 0,
"GRIDID": "PROP",
"GRIDVIEW": "1",
"HITS": 100,
"ORDERBY": "PR_DATESOLD",
"PROFILE": [
{
"PR_NAME": "G*",
"PR_USER1": "GENERATED"
}
],
"sessionID": "#body('Parse_JSON3')['sessionID']"
},
"headers": {
"Accept": "text/json",
"Content-Type": "text/json"
},
"method": "POST",
"uri": "#variables('uri_DefGrid')"
},
"runAfter": {
"Parse_JSON3": [
"Succeeded"
]
},
"type": "Http"
},
"Initialize_Header": {
"inputs": {
"variables": [
{
"name": "Header",
"type": "string",
"value": "{\"Accept\":\"text/json\",\"Content-
Type\":\"text/json\"}"
}
]
},
"runAfter": {
"Initialize_body_login": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_body_DefGrid": {
"inputs": {
"variables": [
{
"name": "body_DefGrid",
"type": "string",
"value": "json(#{body('HTTP_2')})"
}
]
},
"runAfter": {
"HTTP_2": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_body_login": {
"inputs": {
"variables": [
{
"name": "body_login",
"type": "string",
"value": "json(#{triggerBody()})"
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_uri_DefGrid": {
"inputs": {
"variables": [
{
"name": "uri_DefGrid",
"type": "string",
"value": "https://test/SPDEDMHAPI.GRIDGET"
}
]
},
"runAfter": {
"Initialize_uri_login": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_uri_login": {
"inputs": {
"variables": [
{
"name": "uri_login",
"type": "string",
"value": "https://test/SPDEDJSONSERVICE.LOGIN"
}
]
},
"runAfter": {
"Initialize_Header": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Initialize_uri_logout": {
"inputs": {
"variables": [
{
"name": "uri_logout",
"type": "string",
"value": "https://test/SPDEDJSONSERVICE.LOGOUT"
}
]
},
"runAfter": {
"Initialize_body_DefGrid": [
"Succeeded"
]
},
"type": "InitializeVariable"
},
"Logout": {
"inputs": {
"body": {
"method": "logout",
"sessionID": "#body('Parse_JSON3')['sessionID']"
},
"headers": {
"Accept": "text/json",
"Content-Type": "text/json"
},
"method": "POST",
"uri": "#variables('uri_logout')"
},
"runAfter": {
"Initialize_uri_logout": [
"Succeeded"
]
},
"type": "Http"
},
"Parse_JSON3": {
"inputs": {
"content": "#triggerBody()",
"schema": {
"properties": {
"RLS_WHERE": {
"$id": "#/properties/RLS_WHERE",
"type": "string"
},
"contact": {
"type": "string"
},
"error": {
"type": "string"
},
"errorId": {
"type": "string"
},
"fullName": {
"type": "string"
},
"labellanguage": {
"type": "string"
},
"language": {
"type": "string"
},
"message": {
"type": "string"
},
"params": {
"properties": {
"WOPARTSOPT": {
"type": "string"
}
},
"required": [
"WOPARTSOPT"
],
"title": "The Params Schema",
"type": "object"
},
"role": {
"type": "string"
},
"sessionID": {
"type": "string"
},
"success": {
"type": "string"
},
"userEmail": {
"$id": "#/properties/userEmail",
"type": "string"
}
},
"required": [
"success",
"message",
"sessionID",
"language",
"labellanguage",
"error",
"errorId",
"fullName",
"role",
"contact",
"RLS_WHERE",
"userEmail",
"params"
],
"title": "The Root Schema",
"type": "object"
}
},
"runAfter": {
"Initialize_uri_DefGrid": [
"Succeeded"
]
},
"type": "ParseJson"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"HTTP": {
"inputs": {
"body": {
"method": "login",
"password": "qqq",
"username": "qqq"
},
"headers": {
"Accept": "text/json",
"Content-Type": "text/json"
},
"method": "POST",
"uri": "https://test/SPDEDJSONSERVICE.LOGIN"
},
"recurrence": {
"frequency": "Minute",
"interval": 4
},
"type": "Http"
}
}
},
"parameters": {}
}
</code>

Cygnus subscription ngsi_version=2 not implemented

I install the followin docker image of cygnus this. And when i try to make a subscription like the tutorial example i got the following error:
POST /v1/subscriptions&ngsi_version=2 not implemented
This is my POST request:
{
"subscription":{
"description": "One subscription to rule them all",
"subject": {
"entities": [
{
"idPattern": ".*",
"type": "Room"
}
],
"condition": {
"attrs": [
"temperature"
],
"expression": {
"q": "temperature>40"
}
}
},
"notification": {
"http": {
"url": "http://localhost:5050"
},
"attrs": [
"temperature",
"humidity"
]
},
"duration": "P1M",
"throttling": 5
},
"endpoint":{
"host":"151.80.41.166",
"port":"50001",
"ssl":"false",
"xauthtoken":"QsENv67AJj7blC2qJ0YvfSc5hMWYrs"
}
}
How i can enable the ngsi_version 2?

What is the proper way to create a vertex with a set property in Bluemix Graph DB?

I am trying to create a new vertex in the Bluemix Graph DB service. The schema of my DB is as follows.
{"propertyKeys":[{"name":"name","dataType":"String","cardinality":"SINGLE"},{"name":"languages","dataType":"String","cardinality":"SET"},{"name":"picture","dataType":"String","cardinality":"SINGLE"},{"name":"preferred_language","dataType":"String","cardinality":"SINGLE"},{"name":"bytes","dataType":"Integer","cardinality":"SINGLE"},{"name":"github_id","dataType":"String","cardinality":"SINGLE"},{"name":"twitter_id","dataType":"String","cardinality":"SINGLE"},{"name":"language_percentage","dataType":"Float","cardinality":"SINGLE"}],"vertexLabels":[{"name":"person"},{"name":"language"}],"edgeLabels":[{"name":"codes_in","multiplicity":"MULTI"},{"name":"used_by","multiplicity":"MULTI"}],"vertexIndexes":[{"name":"vByName","propertyKeys":["name"],"composite":true,"unique":false},{"name":"vByPreferredLang","propertyKeys":["preferred_language"],"composite":true,"unique":false},{"name":"vByLanguages","propertyKeys":["languages"],"composite":false,"unique":false}],"edgeIndexes":[{"name":"eByName","propertyKeys":["name"],"composite":true,"unique":false},{"name":"eByLanguagePercentage","propertyKeys":["language_percentage"],"composite":true,"unique":false}]}
I am trying to create the vertex with the following POST body
{"name":"Bob","languages":["Node","Python"],"picture":"https://en.gravatar.com/userimage/12148147/46ccae88e5aae747d53e0b1863f72a4e.jpg?size=200","preferred_language":"Node","github_id":"Bob","twitter_id":"Bob"}
However this results in the following error
{"code":"BadRequestError","message":"Property 'languages' with meta properties need to have a 'val'"}
The languages property has a cardinality of SET, what is the right way to create a property for a SET dataType? I would have assumed it was a JSON array.
Ryan, SET isn't a data type. You could also make languages a string with delimited values.
The only types that are supported in the Beta release are : String,Integer,Boolean,Float
The issue is that you're attempting to create a single vertex property with a data type of List<String>, which is not supported in IBM Graph (only JSON-primitive types are supported). To take advantage of a property with a SET data type you'll need to create multiple vertex properties.
It turns out that the distinction between cardinalities and data types in TinkerPop can be a bit of a confusing. Here's an example that should clarify things:
$ curl https://ibmgraph/11/g/schema -XPOST -Hcontent-type:application/json -d '{"propertyKeys":[{"name":"languages","dataType":"String","cardinality":"SET"}]}' | jq .
{
"requestId": "9e0ea947-f9a1-407b-ab1a-cd9b7fd5d561",
"status": {
"message": "",
"code": 200,
"attributes": {}
},
"result": {
"data": [
{
"propertyKeys": [
{
"name": "languages",
"dataType": "String",
"cardinality": "SET"
}
],
"vertexLabels": [],
"edgeLabels": [],
"vertexIndexes": [],
"edgeIndexes": []
}
],
"meta": {}
}
}
$ curl https://ibmgraph/11/g/vertices -XPOST | jq .
{
"requestId": "2ce85907-2aca-4630-876f-31775e74e1de",
"status": {
"message": "",
"code": 200,
"attributes": {}
},
"result": {
"data": [
{
"id": 4112,
"label": "vertex",
"type": "vertex",
"properties": {}
}
],
"meta": {}
}
}
$ curl https://ibmgraph/11/g/vertices/4112 -XPOST -Hcontent-type:application/json -d '{"languages":"Node"}' | jq .
{
"requestId": "52ad6d49-46c9-41aa-9928-5a567099d773",
"status": {
"message": "",
"code": 200,
"attributes": {}
},
"result": {
"data": [
{
"id": 4112,
"label": "vertex",
"type": "vertex",
"properties": {
"languages": [
{
"id": "si-368-sl",
"value": "Node"
}
]
}
}
],
"meta": {}
}
}
$ curl https://ibmgraph/11/g/vertices/4112 -XPOST -Hcontent-type:application/json -d '{"languages":"Python"}' | jq .
{
"requestId": "19886949-6328-4e19-8cac-8fdab37ef2a5",
"status": {
"message": "",
"code": 200,
"attributes": {}
},
"result": {
"data": [
{
"id": 4112,
"label": "vertex",
"type": "vertex",
"properties": {
"languages": [
{
"id": "si-368-sl",
"value": "Node"
},
{
"id": "16q-368-sl",
"value": "Python"
}
]
}
}
],
"meta": {}
}
}

"Only single payment transaction currently supported" on single transaction

I'm a newbie into PayPal integration, and I'm trying to create first payment, I send following request to PayPal Rest API, via their simulator(https://devtools-paypal.com/apiexplorer/PayPalRestAPIs):
{
"intent": "sale",
"payer": {
"payment_method": "paypal",
"funding_instruments": [
{
"credit_card": {
"number": "5277726581534042",
"type": "mastercard",
"expire_month": "9",
"expire_year": "2018",
"links": [
{
"targetSchema": {
"readonly": "true"
},
"schema": {
"readonly": "true"
}
}
]
}
}
],
"payer_info": {
"email": "ostan.marc.buyer#gmail.com"
}
},
"transactions": [
{
"amount": {
"currency": "USD",
"total": "10"
},
"payee": {
"email": "ostan.marc-faciliator#gmail.com"
}
}
],
"redirect_urls": {
"return_url": "yandex.ru",
"cancel_url": "google.com"
},
"links": [
{
"href": "http://google.com",
"rel": "http://yandex.ru",
"targetSchema": {
"readonly": "true"
},
"schema": {
"readonly": "true"
}
}
]
}
The reasponse i get is:
{
"name": "VALIDATION_ERROR",
"details": [
{
"field": "transactions",
"issue": "Only single payment transaction currently supported"
}
],
"message": "Invalid request - see details",
"information_link": "https://developer.paypal.com/webapps/developer/docs/api/#VALIDATION_ERROR",
"debug_id": "08c2dc7a41f64"
}
i just don't know how to make it work..
PayPal just says that im sending 2 payments..
Any help will be highly appreciated
Are you trying to make a card or PayPal wallet payment?
That is, are you planning to charge a card directly, or redirect the user to PayPal?
In your current request you're including data from both options. This might be an issue with the API Explorer if that's what it's giving you.
Try this instead:
curl -v https://api.sandbox.paypal.com/v1/payments/payment \
-H 'Content-Type:application/json' \
-H 'Authorization:Bearer EEwJ6tF9x5WCIZDYzyZGaz6Khbw7raYRIBV_WxVvgmsG' \
-d '{
"intent":"sale",
"redirect_urls":{
"return_url":"http://example.com/your_redirect_url/",
"cancel_url":"http://example.com/your_cancel_url/"
},
"payer":{
"payment_method":"paypal"
},
"transactions":[
{
"amount":{
"total":"7.47",
"currency":"USD"
}
}
]
}'
Or for a card payment:
curl -v https://api.sandbox.paypal.com/v1/payments/payment \
-H "Content-Type:application/json" \
-H "Authorization:Bearer EEwJ6tF9x5WCIZDYzyZGaz6Khbw7raYRIBV_WxVvgmsG" \
-d '{
"intent": "sale",
"payer": {
"payment_method": "credit_card",
"funding_instruments": [
{
"credit_card": {
"number": "5500005555555559",
"type": "mastercard",
"expire_month": 12,
"expire_year": 2018,
"cvv2": 111,
"first_name": "Joe",
"last_name": "Shopper"
}
}
]
},
"transactions": [
{
"amount": {
"total": "7.47",
"currency": "USD"
},
"description": "This is the payment transaction description."
}
]
}'
(Substitute the Authorization header with your own access token).