Skip to main content
Best answer

Input Data and running python code.


I created a Zap that pulls user data when a new membership is created in a gym app call PushPress.  When I get this I want to take input data and write it to a Python script then execute the script to crate an account in another app.

 

Everything works great except im not a Python developer and need to write the input data to the script then execute it.    the part thats not working is the ability to write that info into the script.

 

 

 

import requests
import json

config = {
    'clientApiKey': 'XXX',
    'projectId': 'impact-platform-fd1e8'
}

gymAdminCreds = {
    'email': 'name@email.com',  # REPLACE THIS
    'password': 'Password'  # REPLACE THIS
}
gymId = '888884444'  # GYM id, it's the
userData = {
    'firstName': 'FirstName',
    'email': 'usersemail@gmail.com',
    'lastName': 'LastName',
    'hideScore': False,
    'units': 'imperial',
    'gender': 'Female',
    'birthDate': '1991-02-08'
}

def create_user():
    try:
        signUpResult = requests.post(f"https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key={config['clientApiKey']}",
                                      headers={'Content-Type': 'application/json'},
                                      data=json.dumps({'email': gymAdminCreds['email'], 'password': gymAdminCreds['password'], 'returnSecureToken': True}))
        data = signUpResult.json()
        if not signUpResult.ok:
            error_message = data.get('error', {}).get('message', 'Unknown error occurred')
            raise Exception(error_message)
        
        bearer = 'Bearer ' + data['idToken']

        createUserResult = requests.post(f"http://us-central1-{config['projectId']}.cloudfunctions.net/iw/functions/gym/{gymId}/user",
                                         headers={'accept': 'application/json', 'authorization': bearer, 'content-type': 'application/json'},
                                         data=json.dumps(userData))
        if not createUserResult.ok:
            data = createUserResult.json()
            error_message = data.get('error', {}).get('message', 'Unknown error occurred')
            raise Exception(error_message)
        
        print(f"User {userData['email']} has been created in gym {gymId}")
    except Exception as err:
        print(err)

create_user()

Best answer by Todd HarperBest answer by Todd Harper

Hi @Vic-FiTek!

I’m making the assumption here that your create_user function is set up correctly and doesn’t need any modifications.

To dynamically pull in the Zapier input data, simply type input_data[‘keyName’]:

userData = {
    'firstName': input_data['firstName'],
    'email': input_data['email'],
    'lastName': input_data['lastName'],
    # Presumably, you can remove or comment out the following three items, unless they are required by your API
    'hideScore': False,
    'units': 'imperial',
    'gender': 'Female',
    'birthDate': input_data['birthDate']
}

 

View original
Did this topic help you find an answer to your question?
This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Todd Harper
Forum|alt.badge.img+8
  • Zapier Expert
  • 197 replies
  • Answer
  • May 13, 2024

Hi @Vic-FiTek!

I’m making the assumption here that your create_user function is set up correctly and doesn’t need any modifications.

To dynamically pull in the Zapier input data, simply type input_data[‘keyName’]:

userData = {
    'firstName': input_data['firstName'],
    'email': input_data['email'],
    'lastName': input_data['lastName'],
    # Presumably, you can remove or comment out the following three items, unless they are required by your API
    'hideScore': False,
    'units': 'imperial',
    'gender': 'Female',
    'birthDate': input_data['birthDate']
}

 


  • Author
  • New
  • 1 reply
  • May 13, 2024

Hi Todd!

 

Thank you!  This worked!  Much Appreciated

 

Vic