Skip to main content
Question

Parsing Webflow API request to get User ID from Email via Code Step

  • June 26, 2023
  • 4 replies
  • 147 views

smombartz

Hi!

I’m trying to get the user id “_id” for a specific email from a Webflow Membership API call that returns a JSON list of users. I’m not quite sure how to handle the Webhook output in the code step. using the “full response data” gives me a syntax error.

any help is much appreciated!

 

 

here the code im using:

// inputData is provided by Zapier, and inputData.userlist should be your JSON string
const userList = JSON.parse(inputData.userlist);

// email to find is passed in as inputData.email
const emailToFind = inputData.email;

let userId;
for (let user of userList.users) {
if (user.data.email === emailToFind) {
userId = user._id;
break;
}
}

if (userId) {
console.log(`User ID for ${emailToFind} is ${userId}`);
return { id: userId }; // Returns user ID in a way that it can be used in the next step of your Zap
} else {
console.log(`No user found with email ${emailToFind}`);
throw new Error(`No user found with email ${emailToFind}`); // Stop the Zap execution if no user is found
}

 

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

4 replies

Troy Tessalone
Zapier Orchestrator & Solution Partner
Forum|alt.badge.img+14
  • Zapier Orchestrator & Solution Partner
  • June 26, 2023

Hi @smombartz 

Good question.

Have you checked (try scrolling) to see if there are other data points returned from Zap Step 2 that may be more suitable to use containing the email address? (search by @ which will indicate an email address)


Todd Harper
Forum|alt.badge.img+8
  • Zapier Solution Partner
  • June 26, 2023

Hey there @smombartz!

Welcome to the Zapier community!

Your JavaScript looks correct, but it seems the Full Response Data from your webflow step is showing a URL, not JSON data.

One piece of data from your Webflow step should look the the JSON data below. That is what you should be pulling into your code step. If you don’t see JSON like in the below code, let me know and I can help you troubleshoot further :)

{
"users": [
{
"_id": "6287ec36a841b25637c663df",
"createdOn": "2022-05-20T13:46:12.093Z",
"updatedOn": "2022-05-20T13:46:12.093Z",
"emailVerified": false,
"status": "unverified",
"data": {
"accept-privacy": false,
"accept-communications": false,
"email": "Person.One@home.com",
"name": "Person One"
}
},
{
"_id": "6287ec36a841b25637c663f0",
"createdOn": "2022-05-19T05:32:04.581Z",
"updatedOn": "2022-05-19T05:32:04.581Z",
"emailVerified": false,
"status": "unverified",
"data": {
"accept-privacy": false,
"accept-communications": false,
"email": "Person.Two@home.com",
"name": "Person Two"
}
},
{
"_id": "6287ec36a841b25637c663d9",
"createdOn": "2022-05-17T03:34:06.720Z",
"updatedOn": "2022-05-17T03:34:06.720Z",
"emailVerified": true,
"status": "verified",
"data": {
"accept-privacy": false,
"accept-communications": false,
"email": "Person.Three@home.com",
"name": "Person Three"
}
},
{
"_id": "6287ec37a841b25637c6641b",
"createdOn": "2022-05-15T03:46:09.748Z",
"updatedOn": "2022-05-15T03:46:09.748Z",
"emailVerified": false,
"status": "unverified",
"data": {
"accept-privacy": false,
"accept-communications": false,
"email": "Person.Four@home.com",
"name": "Person Four"
}
},
{
"_id": "6287ec37a841b25637c66449",
"createdOn": "2022-05-15T02:55:38.786Z",
"updatedOn": "2022-05-15T02:55:38.786Z",
"emailVerified": true,
"status": "verified",
"data": {
"accept-privacy": false,
"accept-communications": false,
"email": "Person.Five@home.com",
"name": "Person Five"
}
}
],
"count": 5,
"limit": 5,
"offset": 0,
"total": 201
}

 


smombartz
  • Author
  • New
  • June 26, 2023

thanks @Troy Tessalone and @Todd Harper – was an easy fix after all!

 

in the rather long list i did find a Request Body object mixed in with all the other options which had all the data as JSON!

 


Todd Harper
Forum|alt.badge.img+8
  • Zapier Solution Partner
  • June 27, 2023

@smombartz Glad to hear it!