Recent searches


No recent searches

Error while creating automation from custom app



Posted Dec 30, 2022

I am trying to create an automation from within the custom app, I am following the documentation on Support Site. The script works on Postman, but when I try from the custom app it gives the below error :

Error {"error":"RecordInvalid","description":"Record validation errors","details":{"base":[{"description":"Invalid conditions. You must select at least one condition."}]}} 

below is the code that I am executing.

var _url = '/api/v2/automations.json';
        var settings = {
            url: _url,
            type: 'POST',
            dataType: 'json',
            async: false
        };

        var _data = { "automation": { "title": "Roger Wilco", "all": [{ "field": "status", "operator": "is", "value": "open" }, { "field": "priority", "operator": "less_than", "value": "high" }], "actions": [{ "field": "priority", "value": "high" }] } };

        if (_data) {
            settings.data = JSON.stringify(_data)           
            
        }
        client.request(settings).then(
            function (data) {

                console.log("Automation created" + data)


            },
            function (response) {
                console.error(" Error " + response.responseText);
                //console.log(response);
            });

0

2

2 comments

Hi,

I took a look and was able to work out your issue, simply switch out your line

dataType: "json"

for

contentType: "application/json"

(or just add that line to your settings) and your existing code should work.

And as a bonus, if you change out your console logs to use commas instead of plus signs, the logs will contain the data in an expandable format (instead of showing as [Object object]):

console.log("Automation created", data);

0


Hi Cheryl Lane:

Thanks alot, I followed ur suggestion and it worked . :)

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post