Setting computed inputField values in Zapier CLI applications

I’m working on my Zapier CLI application that includes a resource with a create operation. One of the input fields is marked as computed, and I need to set its value based on data I get from a preceding API call.

Here’s how I have it structured:

create: {
    display: {
        label: 'Add Customer',
        description: 'Creates a new customer record.',
    },
    operation: {
        inputFields: [
            {key: 'client_id', required: true, type: 'integer', label: 'Client', dynamic: 'client.id.name'},
            {key: 'auth_token', required: true, type: 'string', label: 'Auth Token', computed: true},
            {key: 'company_name', required: true, type: 'text', label: 'Company Name'}
        ],
        perform: addCustomer,
        sample: customerSample
    },
}

I need to figure out the correct method to assign the value to the auth_token field in my Zapier CLI setup.

I hit this exact issue building my first Zapier integration. Computed fields get their values during the perform function execution, not through inputFields.

In your addCustomer function, make your API call first to grab the auth token, then assign it to bundle.inputData.auth_token before doing the customer creation. Like this:

const addCustomer = async (z, bundle) => {
    const authResponse = await z.request({
        url: 'your-auth-endpoint',
        method: 'POST'
    });
    
    bundle.inputData.auth_token = authResponse.data.token;
    
    // Now proceed with customer creation using the token
    return z.request({
        url: 'customer-endpoint',
        headers: { 'Authorization': bundle.inputData.auth_token }
    });
};

The computed flag just tells Zapier this field gets populated programmatically instead of by user input.

You’ll want to watch where you’re making that auth token call. I hit performance issues fetching auth tokens for every single customer creation.

What worked better was caching tokens inside the perform function. Check if you’ve got a valid token stored before hitting the API. Store it temporarily and only refresh when it expires.

Also make sure your computed field doesn’t show up in the Zap editor UI. The computed flag should hide it, but double-check users aren’t seeing an empty auth token field they think they need to fill out. That confused my beta testers until I fixed the field definition.

hey, u can manage that directly in your perform func. just get the auth token from your api call and then set bundle.inputData.auth_token = response.token b4 you make ur main request. remember, computed fields fill up during exec, not in the field def.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.