# Mass Update Table Records (With Conditions) From Loaded Variables

**URL:** <https://community.tulip.co/t/mass-update-table-records-with-conditions-from-loaded-variables/6024>\
**Category:** Support, Troubleshooting, & Help\
**Created:** [August 3, 2022, 7:34pm UTC](https://community.tulip.co/t/mass-update-table-records-with-conditions-from-loaded-variables/6024 "2022-08-03T19:34:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gentleboyjones](https://avatars.discourse-cdn.com/v4/letter/g/958977/32.png) [@gentleboyjones](https://community.tulip.co/u/gentleboyjones)\
**Post date:** [August 3, 2022, 7:34pm UTC](https://community.tulip.co/t/mass-update-table-records-with-conditions-from-loaded-variables/6024/1 "2022-08-03T19:34:05Z")

</div>

Hi there -

 ![Screenshot 2022-08-03 111518](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/b/b6ba43b91268b578c0b2916212c96c3e59524c6c.png)

Background:  
Operator calculates a set of statistics from the total sample size & the respective measurements within sample set of a given lot/batch number. Has to manually load each set of calculations into the selected Sample ID # (Bottom Right).

Table Records ID Nomenclature:  
'[Product Code] ‘-’ [Lot Number] ‘-’ [Defect Category] ‘-’ [Sample ID #]

Current Operation:

1. Operator Selects Defect Category to find calculations for from the Defect Classification Table (Upper Right)
2. Selects a Sample ID Record from the Inspection Table Record (Bottom Right)
3. Repeats Calculate to store calculations for each individual sample ID # for the entire sample size.

**Is there a way to batch edit multiple inspection records based currently-loaded variables?**

Tulip Support gave me this, but I do not want to pull from a .CSV.

> import requests  
> import csv  
> import json  
> import time
> 
> #FACTORY = [cooper-usa.tulip.co](http://cooper-usa.tulip.co)  
> FACTORY = ''[cooper-usa.tulip.co](http://cooper-usa.tulip.co)  
> #authorization = ''Basic …==  
> AUTHORIZATION = ‘’'Basic… ==  
> CSV\_FILE = ‘’ #CSV local file name  
> #TABLE\_ID = XooSfizhcWqiMnTxx  
> TABLE\_ID = ''XooSfizhcWqiMnTxx
> 
> endpoint = FACTORY + “/api/v3/tables/” + XooSfizhcWqiMnTxx  
> response = requests.get(endpoint, headers = {‘Authorization’: AUTHORIZATION})  
> print(response.json())
> 
> failedIDs =   
> success\_count = 0  
> failure\_count = 0  
> endpoint = FACTORY + “/api/v3/tables/” + TABLE\_ID + ‘/records’  
> with open(CSV\_FILE, encoding=‘utf8’) as csv\_file:  
> csv\_reader = csv.reader(csv\_file, delimiter=‘,’)  
> line\_count = 0  
> for row in csv\_reader:  
> if line\_count \> 0: # Ignore header rows  
> # Column mapping should follow the format of ‘COLUMN\_ID’: row[COLUMN\_INDEX]  
> # Where COLUMN\_ID is defined by the Tulip Table schema i.e. abcde\_test  
> # and COLUMN\_INDEX is the column number of the CSV (0-indexed)  
> column\_mapping = {  
> ‘id’ : row[2],  
> # Example ’xyz\_part’ : row[3],  
> #’ xyz\_description’ : row[4],
> 
> ```
> }
> columns = json.dumps(column_mapping)
> id = row[2]
> print(column_mapping) 
> response = requests.post(endpoint, headers = {'Authorization': AUTHORIZATION}, data=columns, verify=False)
> if response.status_code != 201:
> print('Posting row {} with id {}, failed with {} response'.format(line_count, id, response))
> failedIDs.append(id)
> failure_count += 1
> else:
> print('Modify successful for ' + id)
> success_count += 1
> time.sleep(0.2)
> line_count += 1
> 
> ```
> 
> print(failedIDs)

---

<div class="post-metadata">

**Author:** ![Pete\_Hartnett](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tulip.co/pete_hartnett/32/3678_2.png) [@Pete\_Hartnett](https://community.tulip.co/u/Pete_Hartnett)\
**Post date:** [August 5, 2022, 2:03pm UTC](https://community.tulip.co/t/mass-update-table-records-with-conditions-from-loaded-variables/6024/2 "2022-08-05T14:03:24Z")

</div>

Hey @gentleboyjones -

Pulled your API Key (the “Basic …” text)from your example just to make sure your data is safe.

What are the chances you can stop by one of the three office hours sessions I hold every week to work through this one? Struggling a little bit to understand exactly the usecase, but i’m sure we can throw together something live on one of these sessions!  
**Tuesday 10AM EST** - [![](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/a/ac5a8b409a762def9b68bb1645e7b7ac1afb2f52.png)Meet](http://meet.google.com/zeo-owar-udg) - New User Office Hours

**Thursday 11AM EST** - [![](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/a/ac5a8b409a762def9b68bb1645e7b7ac1afb2f52.png)Meet](http://meet.google.com/gew-ipre-wfm) - General Office Hours

**Thursday 4PM EST** - [![](https://us1.discourse-cdn.com/flex020/uploads/agilemfg/original/2X/a/ac5a8b409a762def9b68bb1645e7b7ac1afb2f52.png)Meet](http://meet.google.com/grw-orvr-opu) - New User Office Hours

Thanks!  
Pete
