Recipe with Custom Triger, Action and mapping

@yaacovza

You are pretty close. Your ItemMapping would need to be this:
{ id: ‘url’, title: ‘URL’, outboundType: ‘text’, inboundTypes: [‘text’] },
{ id: ‘viewCount’, title: ‘View count’, outboundType: ‘numeric’, inboundTypes: [‘numeric’] },
{ id: ‘likeCount’, title: ‘Like count’, outboundType: ‘numeric’, inboundTypes: [‘numeric’] },
{ id: ‘unlikeCount’, title: ‘Unlike count’, outboundType: ‘numeric’, inboundTypes: [‘numeric’] },
{ id: ‘updateText’, title: ‘URL’, outboundType: ‘text’, inboundTypes: [‘text’] },
{ id: ‘entityId’, title: ‘URL’, outboundType: ‘text’, inboundTypes: [‘text’] },

Your action would look something like this:
Screen Shot 2021-02-02 at 8.18.45 pm

Passing the item mapping values to your endpoint. The column values would be accessed by: $inbound = $request->payload['inboundFieldValues']['itemMapping']; (PHP, but any language is fine)
You can then use the $inbound value as column_values when you create a new item via an API call. I believe it should also include an item_name value in the array that you would need to extract and move to a new variable for the API query. You should also remove the updateText value from the array as this is what you will need for the update.

Once you have the ID returned from the create_item mutation, you can use this to make another API call, create_update using the item_id and the update_text

Hello Mitchell,

Thanks a lot!

I don’t fully understand the solution, if possible could you explain to me how you will build your(s) recipe(s).
I try to make with custom trigger and action but didn’t succeed.
When sending the item mapping I only see the values and not the fields correspondence.

Can you provide me your complete flow?

Regards

If you have working example it’s good to have trigger/action screenshots. I’m just checked built in trigger ‘When an Item is Created’ and it looks bit different and maybe it can be used instead of custom trigger to check this flow.

I try to build simplified recipe and here is my findings:
“When an Item is Created” → “My Custom Action with Mapping”

Posting working example

Looks like When an Item is Created trigger designed to cover only one case when you jut type name for your new record and there is no other fields.

As you can see action can leverage mapping but filds list will be cutted if you forgot about default values for each field. You can check recording - first time integration added with defaults for all fields and second time - with defaults only for one field.
This looks unclear from user perspective WHY we need default values or can we leave them empty

I believe custom trigger can produce similar output with same input fields

@vlad123

Just to confirm, you are looking for this recipe:
When MyEntity is updated, update columns for my item in monday and add an update

Is this correct?

I’m talking about when an entity is created/updated” → “create update an item with mapping and add an update”

@vlad123
Ok great, thanks for confirming:

I have made the bellow just for your purpose, I haven’t done any actually development so just some dummy values, etc… the payload won’t match exactly what I have shown. This is going to be a process so bear with me.

So first, you need to define your Custom Field with type Dynamic Mapping to define your entity structure.

Next, create your Custom Trigger. This is the endpoint that is going to be called when the entity is created or updated. It is up to your logic if you want to use 1 or 2 triggers for this.


The key here is the output fields as this is what is passed to your action. You can include input fields if you need context for your entity, maybe the board_id that the integration is installed on or something. For our use case, we recieve the payload on our server from the entity, process it and then manually call the custom trigger once we have formatted it in the required format. When you call the Custom Trigger subscription URL, you will need to pass through the CustomEntity values as defined by your DynamicFields mapping definition

Next you need to create you action. This should accept the CustomEntityField mapping as an input field. Again, you can include other information like board_id if you need some context. Generally a board_id is ideal so you know where to create the item.


I will come back to how this action is processed later.

Once you have your trigger and action, you can create the recipe. It should take both your custom trigger and your action that you have created.


You still need to allow the user to map which columns are updated with the different dynamic fields. You should select the source entity as your customEntityId which is passed through from your Custom Trigger.

Now, this is the hard bit. Up to this point the monday.com article is pretty easy for you to follow. It explains how you get/store the subscription URL to call your custom trigger, define dynamic fields, etc… The article uses the built in action for Item Mapping, we are going to build our own.

With the action that we have created, you will receive a payload that is something like this:

{
    "payload" : {
        "inboundFieldValues" : {
            "boardId" : 541329092,
            "customEntityId" : {
                "text" : "Hello world",
                "long_text" : "Hello, world?",
                "numbers" : 42
            }
        }
    }
}

Where customEntityId can simply be json_encoded and you can use this as your column_values. You will need to remove the item_name value from this array as it needs to be passed as a different variable in the create_item mutation. For reference, this is the mutation you will be calling.

mutation {
    create_item (board_id: BOARD_ID group_id: GROUP_ID (this can be collected from customEntityId as well), item_name: "new item", column_values: JSON_ENCODED columnValues) {
        id
    }
}

When you run this mutation yourself, you will receive back the new item_id.
You can then call:

mutation {
    create_update (item_id: ITEM_ID_FROM_CREATE_ITEM_MUTATION, body:UPDATE_BODY) {
        id
    }
}

Once you have called the create_update mutation, you will have a new item with the update as well

2 Likes

I try to create custom trigger + custom action and looks like it still need some thing e.g. item values or something like that to properly function
when trigger produce custom entity it can’t be picked by action
here is demonstration

I try something similar before . looks like it’s non trivial case to use custom action with custom trigger together .

@vlad123 Ahh sorry mate, you need to add a dependency to the entity field type.

It needs the boardId so it can query the available columns on the board and allow you to map as required.

You will need to add the dependency to the entityField type and then map this in the recipe

Looks like action should receive BoardId when it specified as dependency. adding dependency itself does not help. I try with existing action, trigger and recreate action trigger and entity.
When recreated it do not allow me to save recipe - button disabled. Unfortunatelly

@vlad123 To be honest, I am not sure why it isn’t working for you.

Can you please send me the screen shots?

If the button is disabled, it is generally because it is missing aa variable in the sentence or an input field hasn’t been mapped

I have a call with Dipro and we find issue. outbound value was incorrect there should be one item instead of array. Thanks a lot

Hi @vlad123,

I’m so glad to hear that the issue has been resolved for you!

Best,
Helen