Using an ARM template function leads to a deserialization error - json

I'm publishing an ARM template to create an alert and am utilizing the subscription() template function to gather the user's subscription, which is to be used in the 'scopes' property
"scopes": "[subscription().id]",
This, however, is leading to a deserialization error "The request content was invalid and could not be deserialized: 'Error converting value \"/subscriptions/abcdef-abcd-abcd-1234-abcdasdj12\" to type 'System.Collections.Generic.List`1[System.String]
The subscription id is properly gathered, however it does not convert to type 'System.Collections.Generic.List`1[System.String].

Changing
"scopes": "[subscription().id]",
to
"Scopes": [
"[subscription().id]"
],
fixed it

Related

Get value from Json list then validate the value appear in list

I want to check the value "train-again-v1-16k" appears in any of the "model_name".
I am able to get the response, then I want to make sure the list contains value by using Dictionary Should Contain Value.
Test case failed:
AttributeError: 'list' object has no attribute 'values'
Please advise what is the correct syntax to check the value in a list.
*** Settings ***
Library Browser
Library String
Library RequestsLibrary
Library Collections
Library RPA.JSON
*** Test Cases ***
001-Models-Deploy
Create Session mysession ${SRS-API-Host}
${response}= GET ${SRS-API-Host}/models_list
${models}= Get values from JSON ${response.json()} $..model_name
Log To Console models is${models}
Dictionary Should Contain Value ${models} 'train-again-v1-16k'
GET Response:
{
"message": "",
"status": "ok",
"valid_model_list": [
{
"corpus_list": [
"test1"
],
"display_name": "16000samplerate-60train-40test-v1-16k",
"language": "NO INFO",
"lexicon": "001_Lex_one_using_001_wav_stm_only",
"model_name": "16000samplerate-60train-40test-v1-16k",
"status": true,
"train_duration": "1.0 Hrs"
},
{
"corpus_list": [
"Corpus3397"
],
"display_name": "train-again-v1-16k",
"language": "NO INFO",
"lexicon": "NTU",
"model_name": "train-again-v1-16k",
"status": true,
"train_duration": "1.33 Hrs"
}
]
}
Get values from JSON returns a list with all matching values, while Dictionary Should Contain Value works with and expects, well, a dictionary object.
Just change the keyword for asserting a value is present with something that works with lists - List Should Contain Value, or just Should Contain:
List Should Contain Value ${models} train-again-v1-16k
By using the Should Contain, the list obtained from Get values from JSON , the specific value is asserted.
*** Settings ***
Library Browser
Library String
Library RequestsLibrary
Library Collections
Library RPA.JSON
Resource ../Resources/BrowserFunctions.robot
Suite Setup Start New Browser
Suite Teardown Close Browser
*** Test Cases ***
001-Models-Deploy
#Verify model appear at SRS API Model List
Create Session mysession ${SRS-API-Host}
${response}= GET ${SRS-API-Host}/models_list
${models}= Get values from JSON ${response.json()} $..model_name
Log To Console models is${models}
Should Contain ${models} sourcemodel8k8020-v1-8k

AWS Step function string/json concatenation

I have orchestrated a data pipe line using AWS Step function.
In last state I want to send a custom notification. I'm using an Intrinsic function States.Format to format my message and subject. It works fine for Context object element. Here, I have tested that in Message parameter.
But it doesn't work with input JSON. This is my input JSON
{
"job-param":{
"pipe-line-name":"My pipe line name", "other-keys":"other values"
}
}
"Success State": {
"Type": "Task",
"Resource": "arn:aws:states:::sns:publish",
"Parameters": {
"Message.$": "States.Format('Execution Id:{}, completed successfully!', $$.Execution.Id)",
"Subject.$": "States.Format('[INFO] {} completed successfully!', $.job-param.pipe-line-name)",
"TopicArn": "arn:aws:sns:us-east-1:************:sns-topic"
},
"End": true
}
While saving this state machine, it gives me following error message:
The value for the field 'Subject.$' must be a valid JSON Path
I checked Input and Result path. They have this value. I can directly use this value as parameter. This is working fine. But I can't format with other string.
"Subject.$": "$.job-param.pipe-line-name"
Alternate approach would be to call lambda to customize and trigger SNS. But I want to avoid that.
Can I request some suggestions to fix this error?
Thanks in advance!
If you want to use any name with - in your JSON then you can write your JSON Path like this:
"Subject.$": "States.Format('[INFO] {} completed successfully!', $['job-param']['pipe-line-name'])",
But it would be easier if you change your input JSON and replace - with _:
"Subject.$": "States.Format('[INFO] {} completed successfully!', $.job_param.pipe_line_name)",

ADF V2 - Web POST method using Dynamic Content and Variable

Very short version
How do I include an ADF Variable inside a JSON POST request, in a Web Activity within ADF?
I feel like this should be a very simple string concatenation, but i can't get it to work
Detail
We have a requirement to run a query / SProc from within ADF, which will return a string containing an error message. That string is to then be passed via the Web Activity in ADF to a Logic App, in order to fire off an email, containing the error.
The setup of the logic app is copied from here:
https://www.mssqltips.com/sqlservertip/5718/azure-data-factory-pipeline-email-notification--part-1/
and then here (part 2)
https://www.mssqltips.com/sqlservertip/5962/send-notifications-from-an-azure-data-factory-pipeline--part-2/
In ADF, I used the Lookup activity, to run a query, which brings back the error (appears to work, the preview returns the correct string)
Then I use the Set Variable activity, to take the output of the lookup and store it in a variable.
Last Step is to fire off the POST using the Web Activity.
With this code (tweaked slightly to remove personal details) in my Web Activity, everything works fine and I receive an email
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "Pipeline finished!",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}
But any attempt to put the contents of the Variable into the Subject part has failed.
This (for example) sends me an email with the subject literally being #variables('EmailSubject')
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "#variables('EmailSubject')",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}
But I've also attempted various other solutions that result in errors or the email subject just containing the literal thing that I put in there (e.g. + #variables('EmailSubject') +).
I also tried storing the entire JSON in the Variable, and then having the Web activity use only the variable, that returned no errors, but also did not send an email.
This attempt:
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "#{variables('EmailSubject')}",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}
Resulted in this input into the web activity - which actually includes the text of the error, which is a bonus ... (text = Job Duration Warning):
{
"url": "https://azureLogicAppsSiteHere",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"body": "{\n \"DataFactoryName\": \"DFNAMEHERE\",\n \"PipelineName\": \"pipeline1\",\n \"Subject\": \"{\"firstRow\":{\"\":\"Job Duration Warning\"},\"effectiveIntegrationRuntime\":\"DefaultIntegrationRuntime (West Europe)\",\"billingReference\":{\"activityType\":\"PipelineActivity\",\"billableDuration\":[{\"meterType\":\"AzureIR\",\"duration\":0.016666666666666666,\"unit\":\"DIUHours\"}]},\"durationInQueue\":{\"integrationRuntimeQueue\":0}}\",\n \"ErrorMessage\": \"Everything is okey-dokey!\",\n \"EmailTo\": \"me#myEmail.com\"\n}\t"
}
But then resulted in this error:
{
"errorCode": "2108",
"message": "{\"error\":{\"code\":\"InvalidRequestContent\",\"message\":\"The request content is not valid and could not be deserialized: 'After parsing a value an unexpected character was encountered: f. Path 'Subject', line 4, position 17.'.\"}}",
"failureType": "UserError",
"target": "Web1",
"details": []
}
[Edit] The PREVIEW from the Lookup Activity is the text: Job Duration Warning BUT when I debug the pipeline, it lets me see the actual Output, which is this:
{
"count": 1,
"value": [
{
"": "Job Duration Warning"
}
],
"effectiveIntegrationRuntime": "DefaultIntegrationRuntime (West Europe)",
"billingReference": {
"activityType": "PipelineActivity",
"billableDuration": [
{
"meterType": "AzureIR",
"duration": 0.016666666666666666,
"unit": "DIUHours"
}
]
},
"durationInQueue": {
"integrationRuntimeQueue": 0
}
}
So it appears that the problem is that the Lookup Output isn't what I thought it was, so the variable can't be used in the Web Activity, as it contains unsupported characters or something along those lines.
I just tested this and it worked ok:
Create a String Parameter with the value Job Duration Warning
Set the Variable value to be #pipeline().parameters.ParamSubject
Include the variable in the web activity with an # in front of it
I then receive my expected email with the right subject. I just don't know how to get the string output of my query, into a variable / parameter, so that i can use it in the web activity.
I don't know how well this applies to other people's issues, but I found a solution that has worked for me.
In the SELECT query within the Lookup Activity - name the output (in my case, I called that column 'Subject'- i.e. SELECT xyz AS Subject
In the Lookup Activity, turn on the setting 'First Row Only'
In the Set Variable Activity, use the code: #activity('Lookup1').output.firstRow.subject
(where 'Lookup1' is the name of your Lookup Activity and Subject is the name of the column you are outputting)
In the Web Activity, reference the variable as follows:
{
"DataFactoryName": "#{pipeline().DataFactory}",
"PipelineName": "#{pipeline().Pipeline}",
"Subject": "#{variables('EmailSubject')}",
"ErrorMessage": "Everything is okey-dokey!",
"EmailTo": "me#myEmail.com"
}

Invalid format of event in WSO2

I am trying to deploy business rules via the API of wso2.
I have tested the siddhi App on the editor , it works correctly. When I deploy it in the dashboard. When sending the data to the url of input, I get this error:
ERROR {org.wso2.extension.siddhi.map.text.sourcemapper.TextSourceMapper} - Invalid format of event because some required attributes are missing in event {
"symbol": "qxyt",
"price": 45.22,
"volume": 33,
"name": "Beldum"
} while needed attributes are [Attribute{id='symbol', type=STRING}, Attribute{id='price', type=FLOAT}, Attribute{id='volume', type=LONG}, Attribute{id='name', type=STRING}] in the stream StockInputStream of siddhi text input mapper.
I have send the json as:
{"event":{
"symbol":"sonido",
"price":45.22,
"volume":33,
"name":"salon"
}}
and
{
"symbol":"sonido",
"price":45.22,
"volume":33,
"name":"salon"
}
but with both I get the same error.
Is wrong the way I'm sending? or how does it is supposed to be received?
Since you are using text mapping you will have to send a comma separated key value pair with new lines in between like below.
"symbol":"sonido",
"price":45.22,
"volume":33,
"name":"salon"
This is a testcase and this is the documentation for text mapper. If you want to send json you will have to use json mapper.

Is there an alternative to "type": "undefined" in JSON?

I'm working with Amazon API Gateway. I am creating a model for an REST API. The model gets hung up on:
"tiers": {
"type": "array",
"items": {
"type": "undefined"
}
}
The API data model uses JSON schema draft 4.
The error returned is:
Invalid model specified: Validation Result: warnings : [], errors :
[Invalid model schema specified]
Anyone run into this before?
Things I've tried:
Removing this property = script creates model
Changing "Undefined" to "null" = script creates model
The "null" seems like the right option but, I've not been able to back it up. Some guidance and/or clarification would be greatly appreciated.
Thanks,
Todd
You don't seem to be actually defining a schema for your data, refer to the API gateway docs to re-define your model.
undefined is not a valid json value, even though it is valid in javascript. From the official json standard (ECMA-404, Section 5):
A JSON value can be an object, array, number, string, true, false, or
null.
For json, use null instead of undefined: { "something": null }
Using null instead of undefined is definitely not ideal, but it's a standard you can count on when consuming third-party services.