It looks like you’re receiving a POST request with a JSON payload in the body. The body object contains an array called fields, which seems to contain various pieces of information. Each object in the fields array has an id, label, type, and value. The value can be a string, an array, or an object, depending on the type. For example, the first object in the fields array has a type of FileUpload and its value is an array. The second object has a type of MultipleChoice and its value is a string. If you need to access specific data from this payload in your workflow, you can do so using the steps.trigger.event.body object. For example, to access the value of the second object in the fields array, you would use steps.trigger.event.body.fields[1].value. Let me know if you need help with anything else!
thanks. What if I need value and the place in the array might change, can I get value by its lable?
let’s say I need the value of “lakoach_recID” which is rec70gTsYhVvb6kjh in this example. How can I map that?
Yes, you can get the value by its label. You can iterate over the fields array and find the object where the label is equal to “lakoach_recID”. Here’s how you can do it: const fields = steps.trigger.event.body.fields; const lakoach_recID = fields.find(field => field.label === 'lakoach_recID').value; In this code, find will return the first object in the fields array where the label is “lakoach_recID”. The .value property of this object is the value you’re looking for. If no such object is found, find will return undefined, and trying to access the .value property will result in an error. You might want to add error handling to this code to handle such a situation.
Yes, you can use the props section in a Pipedream component to define inputs that can be configured by the user. However, the props are static and cannot be dynamically populated based on the incoming request. For example, if you want to allow the user to specify the label to look for, you could define a prop like this: props: { labelToFind: { type: "string", label: "Label to find", description: "Enter the label of the field you want to find the value for", }, }, Then in the run method, you could use this prop to find the value: async run({steps, $}) { const fields = steps.trigger.event.body.fields; const value = fields.find(field => field.label === this.labelToFind).value; // ... } In this way, the user can specify the label they are interested in when they configure the component. However, the value of labelToFind cannot be dynamically populated based on the incoming request. It must be set by the user when they configure the component.
In the case of using the Airtable “Get Record” module, you don’t need to write a run method because it’s a pre-built action provided by Pipedream. You just need to configure the module with the necessary parameters, such as the Base ID, Table Name, and Record ID. If you want to use the value of “lakoach_recID” as the Record ID, you would first need to extract it from the incoming request in a previous step of your workflow. Here’s an example of how you could do that: export default defineComponent({ async run({steps, $}) { const fields = steps.trigger.event.body.fields; const lakoach_recID = fields.find(field => field.label === 'lakoach_recID').value; $.export('lakoach_recID', lakoach_recID); }, }); This code would be in a code step before the “Get Record” module. It extracts the value of “lakoach_recID” from the incoming request and exports it, making it available for use in subsequent steps. Then, in the “Get Record” module, you would use {{steps.previous_step.lakoach_recID}} as the Record ID, where previous_step is the name of the step where you extracted the “lakoach_recID” value. This will dynamically populate the Record ID with the value of “lakoach_recID” from the incoming request.
Sure, if you want to map all fields in the JSON to their respective values, you can do so by iterating over the fields array and creating a new object where the keys are the labels and the values are the values. Here’s how you can do it: export default defineComponent({ async run({steps, $}) { const fields = steps.trigger.event.body.fields; const mappedFields = {}; for (const field of fields) { mappedFields[field.label] = field.value; } $.export('mappedFields', mappedFields); }, }); In this code, mappedFields is an object where the keys are the labels from the fields array and the values are the corresponding values. This object is then exported, making it available for use in subsequent steps.