versionone Post to create task fails - json

Using json w/ Python requests to create task, fails with:
{ "_type": "Error", "error": "Bad Request", "exceptions": [ { "type": "DataException", "message": "Violation'NotSupported" } ] }
URL used: https://www5.v1host.com/INSTANCE/rest-1.v1/Data/Task
Here is the body of the request: (headers are the usual; Authorization, Content-Type, Accept)
{
"Attributes": {
"Parent": {
"value": {
"href": "/INSTANCE/rest-1.v1/Data/Story/1520179",
"idref": "Story:1520179"
},
"act": "set"
},
"Category": {
"value": {
"href": "/INSTANCE/rest-1.v1/Data/TaskCategory/113",
"idref": "TaskCategory:113"
},
"act": "set"
},
"Source": {
"value": {
"href": "/INSTANCE/rest-1.v1/Data/TaskSource/954121",
"idref": "TaskSource:954121"
},
"act": "set"
},
"Status": {
"value": {
"href": "/INSTANCE/rest-1.v1/Data/TaskStatus/123",
"idref": "TaskStatus:123"
},
"act": "set"
},
"Owners": {
"value": {
"href": "/INSTANCE/rest-1.v1/Data/Member/1337179",
"idref": "Member:1337179"
},
"act": "add"
},
"Order": {
"value": "1073828387",
"act": "set"
},
"ToDo": {
"value": 6,
"act": "set"
},
"DetailEstimate": {
"value": 6,
"act": "set"
},
"Description": {
"value": "<p>Meetings/Planning<br>Scrum attendance (x2)<br>Team meetings<br>Sprint planning<br>Demo coordination<br>Management meetings (x2)<br>Daily Progress Reporting</p>",
"act": "set"
},
"Name": {
"value": "Scrum Meetings/Team Mgmt",
"act": "set"
}
}
}
Any ideas on what is wrong with this request? (Found very few examples of this type of operation)

Related

Map step function result and extract certain keys

I have the following output coming from a step function task: ListObjectsV2
{
"Contents": [
{
"ETag": "\"86c12c034bc6c30cb89b500b954c188f\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_1.csv",
"LastModified": "2023-02-09T13:46:20Z",
"Size": 796014,
"StorageClass": "STANDARD"
},
{
"ETag": "\"58e4a770e0f66073b00d185df500f07f\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_2.csv",
"LastModified": "2023-02-09T13:47:20Z",
"Size": 934038,
"StorageClass": "STANDARD"
},
{
"ETag": "\"460abd0de64d5cb67e8f0d46878cb1ef\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_3.csv",
"LastModified": "2023-02-09T13:46:57Z",
"Size": 794264,
"StorageClass": "STANDARD"
},
{
"ETag": "\"1bfedc3dc92e4ba8d04e24b9b5a0ed58\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_4.csv",
"LastModified": "2023-02-09T13:46:24Z",
"Size": 788756,
"StorageClass": "STANDARD"
},
{
"ETag": "\"9d6c434ce5ebdf203a790fbcf19338dc\"",
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_5.csv",
"LastModified": "2023-02-09T13:47:07Z",
"Size": 831156,
"StorageClass": "STANDARD"
}
],
"IsTruncated": false,
"KeyCount": 5,
"MaxKeys": 1000,
"Name": "vita-internal-text-classification-dev-183576513728",
"Prefix": "55271f52fffe4461a2ee3228ebb97157"
}
I want to have an array containing only the Key key, to pass to the next state, like so:
[
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_1.csv",
},
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_2.csv",
},
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_3.csv",
},
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_4.csv",
},
{
"Key": "55271f52fffe4461a2ee3228ebb97157/input/batch_5.csv",
}
]
So far I've tried setting the ResultPath to:
$.Contents[*].Key
$.Contents[*].['Key']
What I get is:
[
"55271f52fffe4461a2ee3228ebb97157/input/batch_1.csv",
"55271f52fffe4461a2ee3228ebb97157/input/batch_2.csv",
"55271f52fffe4461a2ee3228ebb97157/input/batch_3.csv",
"55271f52fffe4461a2ee3228ebb97157/input/batch_4.csv",
"55271f52fffe4461a2ee3228ebb97157/input/batch_5.csv",
]
But I've gotten bad output from that, any help?
The way I've solved this is to use an Inline Map state with a Pass state to build the necessary format. You can see this pattern in an example here for how to use Step Functions Distributed Map to bulk delete objects from S3. You can see this in the inner Create Object Identifier Array Map state. If you were doing this in Standard Workflows, this could be a cost concern given the number of state transitions involved. But since in the Item Processor I'm using Express Workflows, which are billed by duration (and these are super fast), it works pretty well.
{
"Comment": "A state machine to bulk delete objects from S3 using Distributed Map",
"StartAt": "Confirm Bucket Provided",
"States": {
"Confirm Bucket Provided": {
"Type": "Choice",
"Choices": [
{
"Not": {
"Variable": "$.bucket",
"IsPresent": true
},
"Next": "Fail - No Bucket"
}
],
"Default": "Check for Prefix"
},
"Check for Prefix": {
"Type": "Choice",
"Choices": [
{
"Not": {
"Variable": "$.prefix",
"IsPresent": true
},
"Next": "Generate Parameters - Without Prefix"
}
],
"Default": "Generate Parameters - With Prefix"
},
"Generate Parameters - Without Prefix": {
"Type": "Pass",
"Parameters": {
"Bucket.$": "$.bucket",
"Prefix": ""
},
"ResultPath": "$.list_parameters",
"Next": "Delete Objects from S3 Bucket"
},
"Fail - No Bucket": {
"Type": "Fail",
"Error": "InsuffcientArguments",
"Cause": "No Bucket was provided"
},
"Generate Parameters - With Prefix": {
"Type": "Pass",
"Next": "Delete Objects from S3 Bucket",
"Parameters": {
"Bucket.$": "$.bucket",
"Prefix.$": "$.prefix"
},
"ResultPath": "$.list_parameters"
},
"Delete Objects from S3 Bucket": {
"Type": "Map",
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "DISTRIBUTED",
"ExecutionType": "EXPRESS"
},
"StartAt": "Create Object Identifier Array",
"States": {
"Create Object Identifier Array": {
"Type": "Map",
"ItemProcessor": {
"ProcessorConfig": {
"Mode": "INLINE"
},
"StartAt": "Create Object Identifier",
"States": {
"Create Object Identifier": {
"Type": "Pass",
"End": true,
"Parameters": {
"Key.$": "$.Key"
}
}
}
},
"ItemsPath": "$.Items",
"ResultPath": "$.object_identifiers",
"Next": "Delete Objects"
},
"Delete Objects": {
"Type": "Task",
"Next": "Clear Output",
"Parameters": {
"Bucket.$": "$.BatchInput.bucket",
"Delete": {
"Objects.$": "$.object_identifiers"
}
},
"Resource": "arn:aws:states:::aws-sdk:s3:deleteObjects",
"Retry": [
{
"ErrorEquals": [
"States.ALL"
],
"BackoffRate": 2,
"IntervalSeconds": 1,
"MaxAttempts": 6
}
],
"ResultSelector": {
"Deleted.$": "$.Deleted",
"RetryCount.$": "$$.State.RetryCount"
}
},
"Clear Output": {
"Type": "Pass",
"End": true,
"Result": {}
}
}
},
"ItemReader": {
"Resource": "arn:aws:states:::s3:listObjectsV2",
"Parameters": {
"Bucket.$": "$.list_parameters.Bucket",
"Prefix.$": "$.list_parameters.Prefix"
}
},
"MaxConcurrency": 5,
"Label": "S3objectkeys",
"ItemBatcher": {
"MaxInputBytesPerBatch": 204800,
"MaxItemsPerBatch": 1000,
"BatchInput": {
"bucket.$": "$.list_parameters.Bucket"
}
},
"ResultSelector": {},
"End": true
}
}
}

whatsapp cloud api template object issue to send from postman

I'm trying to send the whatsapp cloud template from postman.
I created a template in whatsapp cloud with header media image,
body content,footer and two buttons.
the response of the templates when i use get api is as below
{
"name": "trns_btn_img_header_XXX",
"components": [
{
"type": "HEADER",
"format": "IMAGE",
"example": {
"header_handle": [
"https://img.url.com"
]
}
},
{
"type": "BODY",
"text": "Body message"
},
{
"type": "FOOTER",
"text": "ftr optioal"
},
{
"type": "BUTTONS",
"buttons": [
{
"type": "QUICK_REPLY",
"text": "qrbtnone"
},
{
"type": "QUICK_REPLY",
"text": "qrbtntwo"
}
]
}
],
"language": "en_US",
"status": "APPROVED",
"category": "TRANSACTIONAL",
"id": "17XX209448XXXXXX"
}
I tried the template json object in postman is as below
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "{{message_to}}",
"type": "template",
"template": {
"name": "trns_btn_img_header_XXX",
"language": {
"code": "en_US"
},
"components": [
{
"type": "header",
"parameters": [
{
"type": "image",
"image": {
"link": "https://img.jpg.com"
}
}
]
},
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Body message from pm"
},
]
},
{
"type": "footer",
"parameters": [
{
"type": "text",
"text": "footer message from pm"
},
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": "0",
"parameters": [
{
"type": "text",
"text": "btnone"
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": "1",
"parameters": [
{
"type": "text",
"text": "btntwo"
}
]
}
]
}
}
the response error is "error": {
"message": "(#132000) Number of parameters does not match the expected number of params"
Make sure and correct the below things in send message endpoint request,
Don't need to pass body component if there are no parameters in the body text, if there are parameters then you need to pass only that parameters text in the separate object of parameters in index order
Don't need to pass the footer component because it is static when you create a template
the quick_reply button type, use type as "payload" instead of "text" in parameters
{
"type": "button",
"sub_type": "quick_reply",
"index": "1",
"parameters": [
{
"type": "payload",
"payload": "btntwo"
}
]
}
Below object worked for me
{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "{{message_to}}",
"type": "template",
"template": {
"name": "trns_btn_img_header_XXX",
"language": {
"code": "en_US"
},
"components": [
{
"type": "header",
"parameters": [
{
"type": "image",
"image": {
"link": "https://www.w3schools.com/html/pic_trulli.jpg"
}
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": "0",
"parameters": [
{
"type": "payload",
"payload": "btntwo"
}
]
},
{
"type": "button",
"sub_type": "quick_reply",
"index": "1",
"parameters": [
{
"type": "payload",
"payload": "btnto"
}
]
}
]
}
}

JSON formatting for Terraform API

I am trying to create a JSON file that will add env variables to a TFE workspace via API.. I am new to JSON so bear with me.. below is what I am trying to use but I can’t seem to get the brackets or formatting correct.. can someone help me out?
{
"data": {
"type":"vars",
"attributes": {
"key":"ID1",
"value":"xxxxxx",
"description":"",
"category":"terraform",
"hcl":false,
"sensitive":false
}
}
"data": {
"type":"vars",
"attributes": {
"key":"ID2",
"value":"xxxxxx",
"description":"",
"category":"terraform",
"hcl":false,
"sensitive":false
}
}
"data": {
"type":"vars",
"attributes": {
"key":"ID3",
"value":"xxxxxx",
"description":"",
"category":"terraform",
"hcl":false,
"sensitive":true
}
}
"data": {
"type":"vars",
"attributes": {
"key":"ID4",
"value":"xxxxxx",
"description":"",
"category":"terraform",
"hcl":false,
"sensitive":true
}
}
}
The following is a valid JSON payload:
{
"data": [
{
"type": "vars",
"attributes": {
"key": "ID1",
"value": "xxxxxx",
"description": "",
"category": "terraform",
"hcl": false,
"sensitive": false
}
},
{
"type": "vars",
"attributes": {
"key": "ID2",
"value": "xxxxxx",
"description": "",
"category": "terraform",
"hcl": false,
"sensitive": false
}
},
{
"type": "vars",
"attributes": {
"key": "ID3",
"value": "xxxxxx",
"description": "",
"category": "terraform",
"hcl": false,
"sensitive": true
}
},
{
"type": "vars",
"attributes": {
"key": "ID4",
"value": "xxxxxx",
"description": "",
"category": "terraform",
"hcl": false,
"sensitive": true
}
}
]
}

Cannot determine what property value is empty?

When running AWS CloudFormation with the below template(part of a pre-existing nested stack), I am getting a failure that "Property Value cannot be empty." for both of the lambda items I am trying to create CloudWatch alarms for. I have tried to run it as part of the nested stack as well as the template by itself to no avail. Can anyone offer any insight?
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Creation of CloudWatch Alarms",
"Resources": {
"CLFirstLambdaAlarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmName": "CLFirstLambdaErrors",
"AlarmDescription": "Alarms when an error occurs on the first lambda",
"AlarmActions": [{ "Ref": "AlarmNotificationTopic" }],
"MetricName": "Errors",
"Namespace": "AWS/Lambda",
"Dimensions": [{
"Name": "first-lambda"
},
{
"Value": { "Fn::ImportValue": "CLFirstLambda" }
}
],
"ComparisonOperator": "GreaterThanOrEqualToThreshold",
"EvaluationPeriods": "1",
"Period": "60",
"Unit": "Count",
"Statistic": "Sum",
"Threshold": "1",
"TreatMissingData": "notBreaching"
}
},
"CLSecondLambdaAlarm": {
"Type": "AWS::CloudWatch::Alarm",
"Properties": {
"AlarmName": "CLSecondLambdaErrors",
"AlarmDescription": "Alarms when an error occurs on the second lambda",
"AlarmActions": [{ "Ref": "AlarmNotificationTopic" }],
"MetricName": "Errors",
"Namespace": "AWS/Lambda",
"Dimensions": [{
"Name": "second-lambda"
},
{
"Value": { "Fn::ImportValue": "CLSecondLambda" }
}
],
"ComparisonOperator": "GreaterThanOrEqualToThreshold",
"EvaluationPeriods": "1",
"Period": "60",
"Unit": "Count",
"Statistic": "Sum",
"Threshold": "1",
"TreatMissingData": "notBreaching"
}
},
"AlarmNotificationTopic": {
"Type": "AWS::SNS::Topic",
"Properties": {
"TopicName": "cl-alarm-topic",
"Subscription": [{
"Endpoint": "me#domain.com",
"Protocol": "email"
}]
}
}
},
"Outputs": {
"AlarmNotificationTopicArn": {
"Description": "ARN of AlarmNotificationTopic",
"Value": { "Ref" : "AlarmNotificationTopic" },
"Export": { "Name" : "AlarmNotificationTopic" }
}
}
}
The CloudFormation Linter gives more detailed error messages:
E3003 Property Value missing at Resources/CLFirstLambdaAlarm/Properties/Dimensions/0
template.json:13:30
E3003 Property Name missing at Resources/CLFirstLambdaAlarm/Properties/Dimensions/1
template.json:16:19
E3003 Property Value missing at Resources/CLSecondLambdaAlarm/Properties/Dimensions/0
template.json:37:30
E3003 Property Name missing at Resources/CLSecondLambdaAlarm/Properties/Dimensions/1
template.json:40:19
AWS::CloudWatch::Alarm
AWS::CloudWatch::Alarm.Dimension
Try these AWS::CloudWatch::Alarm.Dimensions properties instead:
"Dimensions": [{
"Name": "first-lambda",
"Value": { "Fn::ImportValue": "CLFirstLambda" }
}
],
"Dimensions": [{
"Name": "second-lambda",
"Value": { "Fn::ImportValue": "CLSecondLambda" }
}
],

How to get a value of a object from its foreign key?

Im using Backand to store my data. I have an object, Events, that references another object, Locations.
{
"name": "events",
"fields": {
"eventCommentsId": {
"collection": "comments",
"via": "eventId"
},
"tags": {
"collection": "events_tags",
"via": "event"
},
"users": {
"collection": "users_events",
"via": "event"
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
{
"name": "locations",
"fields": {
"events": {
"collection": "events",
"via": "locationId"
},
"name": {
"type": "text"
},
"geo": {
"type": "point"
}
}
}
When I try to display the location of the event, I can only get the value of locationID. I want the actual name of the location, not the id. How do I do that?
<ion-list>
<ion-item class="item item-thumbnail-left" ng-repeat="event in events" type="item-text-wrap" href="#/event-detail/{{event.id}}">
<h2>{{event.name}}</h2>
<p><i class="ion-location"></i> {{event.locationId.name}}</p>
<ion-option-button class="button-assertive" ng-click="deleteEvent(event.id)">
Delete
</ion-option-button>
</ion-item>
</ion-list>
angular code
.service('EventService', function ($http, Backand) {
var baseUrl = '/1/objects/';
var objectName = 'events/';
function getUrl() {
return Backand.getApiUrl() + baseUrl + objectName;
}
function getUrlForId(id) {
return getUrl() + id;
}
getEvents = function () {
return $http.get(getUrl());
};
addEvent = function(event) {
return $http.post(getUrl(), event);
}
deleteEvent = function (id) {
return $http.delete(getUrlForId(id));
};
getEvent = function (id) {
return $http.get(getUrlForId(id));
};
return {
getEvents: getEvents,
addEvent: addEvent,
deleteEvent: deleteEvent,
getEvent: getEvent
}
})
.controller('FeedCtrl', ['$scope', '$ionicModal', '$ionicSideMenuDelegate', 'EventService', function($scope, $ionicModal, $ionicSideMenuDelegate, EventService) {
$scope.events = [];
$scope.input = {};
function getAllEvents() {
EventService.getEvents()
.then(function (result) {
$scope.events = result.data.data;
});
}
$scope.addEvent = function() {
EventService.addEvent($scope.input)
.then(function(result) {
$scope.input = {};
getAllEvents();
});
}
$scope.deleteEvent = function(id) {
EventService.deleteEvent(id)
.then(function (result) {
getAllEvents();
});
}
getAllEvents();
}])
There are two options. You can either use the descriptive value in the __metadata of each object like this:
request: https://api.backand.com/1/objects/events?pageSize=20&pageNumber=1
response:
{
"totalRows": 2,
"data": [
{
"__metadata": {
"id": "1",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 1,
"name": "knicks vs warriors",
"date": null,
"time": null,
"info": "",
"locationId": "1"
},
{
"__metadata": {
"id": "2",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 2,
"name": "knicks vs cavs",
"date": null,
"time": null,
"info": "",
"locationId": "1"
}
]
}
or you can do a deep request and get the value in the relatedObjects
request: https://api.backand.com/1/objects/events?pageSize=20&pageNumber=1&deep=true
response:
{
"totalRows": 2,
"data": [
{
"__metadata": {
"id": "1",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 1,
"name": "knicks vs warriors",
"date": null,
"time": null,
"info": "",
"locationId": "1"
},
{
"__metadata": {
"id": "2",
"fields": {
"id": {
"type": "int",
"unique": true
},
"name": {
"type": "string"
},
"date": {
"type": "datetime"
},
"time": {
"type": "datetime"
},
"info": {
"type": "text"
},
"locationId": {
"object": "locations"
}
},
"descriptives": {
"locationId": {
"label": "Madison Square Garden",
"value": "1"
}
},
"dates": {
"date": "",
"time": ""
}
},
"id": 2,
"name": "knicks vs cavs",
"date": null,
"time": null,
"info": "",
"locationId": "1"
}
],
"relatedObjects": {
"locations": {
"1": {
"__metadata": {
"id": "1",
"fields": {
"id": {
"type": "int",
"unique": true
},
"events": {
"collection": "events",
"via": "locationId"
},
"name": {
"type": "text"
},
"geo": {
"type": "point"
}
},
"descriptives": {},
"dates": {}
},
"id": 1,
"events": null,
"name": "Madison Square Garden",
"geo": [
40.7505,
73.9934
]
}
}
}
}
search for Madison Square Garden as the name of the location to understand the JSON structure.
You can set the descriptive field in the Object Settings