Best answer

Is it possible to get the origination source for my inputFields values?

  • 14 July 2022
  • 6 replies
  • 121 views

Userlevel 1

Background:


I am developing a Zapier app (via CLI), where I’m adding a new `create` action with a hidden `trigger` for populating results via a `dynamic` attribute for `inputFields`.

zapier-platform-core: `v11.2.0`


Question Clarification:

 

For one of my `inputFields` with `key: “campaign_id”`, I use the `dynamic` attribute to allow users to pick from a designated dropdown list for values that I can trust (the values are populated from an API call for specific “campaign types” that are allowed for this action); this works great as I can always trust that the value for `campaign_id` will be a valid option.

However, users can also input their own value for `campaign_id` (whether copy-and-pasting, or pulling from a previous Zap step), this is fine as it provides the user with more flexibility. BUT I can no longer trust the `campaign_id` value when this is used; to address this, my creates perform function has to do a pre-flight `GET /api/campaigns/:campaign_id` request to confirm that the `response.campaign_type` is valid before I can perform the actual functionality needed in my creates perform.

If possible, I would like to **ONLY** do the confirmation pre-flight API request **IF** (and only if) the `campaign_id` value was not selected from my `dynamic` dropdown; I already know that value is valid if it comes from my `dynamic` dropdown, I only want to make the API request if the value originated from the user in some other way.


Is it possible to do any of the following?

  1. get some sort of “origination source” for an `inputField` value (`campaign_id` in my case)?
     
  2. or, is there some other workaround that can be used for me to identify that the `campaign_id` was set from my `dynamic` list?
icon

Best answer by connorz 15 July 2022, 21:24

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

6 replies

Userlevel 1

If you want any clarification or have any other response, feel free to let me know. You can also get world-class help from our platform support team by contacting us while logged in at the developer contact form.

Wait, haha I didn’t realize there was a place I could get support. Thank you for pointing this out @shalgrim ! I spent awhile trying to find out where I could ask this question and ended up posting here in this forum instead of on the deprecated Slack server.

Userlevel 3
Badge +6

Hey Chris, to the best of my knowledge, there’s no such origination source property that will explicitly say whether an input field was mapped using a dropdown choice or if it was mapped as a custom value (the output of a previous step). 

However, there are two options that might be worth exploring. 

First, you can check the field’s value in bundle.inputDataRaw:

  • If the input field was mapped using a dropdown choice, the dropdown value should be stored in bundle.inputDataRaw literally.
  • If the field was mapped as a custom value (passed from a previous step), the value will be formatted as a “curly” reference to the previous step, like `{{stepID__previous_key}}`.

In this way, you may be able to only make the pre-flight call if the field’s value in bundle.inputDataRaw is formatted as a curly.

  • One important caveat: there’s no distinction between values that have been chosen from the dropdown and those typed statically into the field. Both are stored in bundle.inputDataRaw in the same format.

Second, perhaps more of a supplementary option: If one doesn’t already exist, it can sometimes be helpful to add a similar search action. For example, if your API allows for finding a campaign by name, something like a “Find Campaign” action might let users pass campaign names into the search step, which would presumably return the corresponding id. That can sometimes allow for a bit more flexibility and increase the likelihood that a mapped custom value will be a valid one. That said, this may not make sense in certain cases and depends on what your API supports. 

Userlevel 6
Badge +8

Hi @chris_skipio !

It sounds like you’re trying to write your app to only make the action call if they’ve entered a valid ID into that step. Is that right?

First, I want to mention that the case where the user selected it from a dynamic drop-down itself wouldn’t prevent a bad ID from being in the step. Consider the case where the campaign was valid, the user selected it from a drop-down, but two months later the campaign is deleted or for some other reason the user doesn’t have access to it. In that case you would detect that they had selected it from a drop-down but the ID would still be invalid.

Instead of trying to manage every way an incorrect ID would go wrong, my suggestion would be for the API to reply with the appropriate 4xx code on an error and to handle raising that error message to the user using the error handling aspects of the platform.

If you want any clarification or have any other response, feel free to let me know. You can also get world-class help from our platform support team by contacting us while logged in at the developer contact form.

Userlevel 1

Consider the case where the campaign was valid, the user selected it from a drop-down, but two months later the campaign is deleted or for some other reason the user doesn’t have access to it.

Yes your insight is correct @shalgrim, the 2nd API call will respond with the correct `4XX` codes if the Campaign no longer exists (or the user no longer has access to it); so I am successfully capturing this case regardless. The 1st pre-flight API call will also check for `4XX` codes, but is primarily used for when the Campaign is found but where it has the incorrect “type”. (Unfortunately the 2nd API call is asynchronous and isn’t able to tell the difference between a valid/invalid campaign type in-time to respond appropriately; I need to capture that error manually with the pre-flight request.)

 

Userlevel 1

Thank you @Zip Zorpler, your suggestions sound very promising; I’ll be checking out your first option to see how the `bundle.inputDataRaw` data differs from when the value is from a custom-input type vs select from the dropdown list. Your highlighted caveat might be a problem though as this won’t be fully reliable when the user types in the value 🤔 (though I imagine that would be a lower % of users doing that). I might just need to make the 2 API requests regardless until the API creates a synchronous endpoint that will check the type for me.

 

Your second option is also a good idea; I have attempted to add searching as a sort of filter to the dropdown results (so the user doesn’t need to keep clicking on “Load More” until they find what they’re looking for) but found that the dropdown is very basic and doesn’t allow for any `inputFields` for my API requests to use; however adding this search ability as a separate step didn’t occur to me and is something I’ll consider.

 

Based off of the research I’ve already done, I think your 2 options are the best available options to me. Thank you for taking time to share them with them.

Userlevel 1

Or is it possible for me to store an array of the `campaign_id`’s that my `dynamic` dropdown provided to the end-user to cross-reference in the `perform` function? 🤔 That might be the easiest thing to do, just not sure how I would be able to store values found from a `trigger` perform to be later referenced in a separate `create` perform?