Python program to send updates to a vendor’s API works accept for processing the return response

This is my first attempt at using an API. I went with Python and everything seemed to work — I was able to send 17,500+ records to a vendor and they are showing up perfect on their website. The problem is that the vendor is using different IDs then we are. I work for a public school system and this is for our bus transportation. I pass the vendor bus stops and in their response they pass me the ID that was created. I then have to take that ID and pass it into a SQL Server procedure to update a cross reference table. I tested this by just sending a single record and it worked great, so I turned on the process to push all 17,500+. When I checked the cross reference table, I’m seeing unexpected results. Of the 17,500 records, only 13 got updated with the Vendor ID. On top of that, there is a status field that should have gotten updated from “New” to “Processed”, and it didn’t get updated even in the 13 records that got the Vendor ID updated.

I don’t know what I did wrong, but I’m hoping somebody can spot the issue. Here is my python code:

import pyodbc as db 
import requests

url = "<vendor URL>"

def GetData():
    connVendorData = db.connect(<Driver Info>)
    connVendorData.setdecoding(db.SQL_CHAR, encoding='latin1')
    connVendorData.setencoding('latin1')
    
    cursor_Vendor = connVendorData.cursor()
    cursor_Vendor.execute('''exec get_addressBookUpdates''')

    for row in cursor_Vendor: 
        payload = {
            "geofence": { "circle": {
                    "latitude": str(row.latitude),
                    "longitude": str(row.longitude),
                    "radiusMeters": str(row.radius)
                } },
            "formattedAddress": row.formattedAddress,
            "longitude": str(row.longitude),
            "latitude": str(row.latitude),
            "name": row.addressBookTitle
        }
        headers = {
            "accept": "application/json",
            "content-type": "application/json",
            "authorization": "<vendor token>"
        }

        response = requests.post(url, json=payload, headers=headers)

        connMyCompanyData = db.connect(<Driver Info>)
        connMyCompanyData.setdecoding(db.SQL_CHAR, encoding='latin1')
        connMyCompanyData.setencoding('latin1')

        cursor_MyCompany = connMyCompanyData.cursor()
        cursor_MyCompany.execute('''exec update_stopIDs_xref_AfterProcessing ?, ?''', row.status, response.text)
        
GetData()

And here is the stored procedure that is updating the cross reference table:

alter PROC update_stopIDs_xref_AfterProcessing
@status VARCHAR(25),
@json NVARCHAR(MAX)

AS

SET NOCOUNT ON 

--Test Parms
--DECLARE @json nvarchar(MAX)
--DECLARE @status VARCHAR(25) = 'New'

--SET @json = '{
--  "data": {
--    "id": "137279769",
--    "name": "MILLGATE RD @ LA GRANGE RD",
--    "createdAtTime": "2024-05-12T15:12:47.880383692Z",
--    "formattedAddress": "MILLGATE RD @ LA GRANGE RD",
--    "geofence": {
--      "circle": {
--        "latitude": 38.27088968,
--        "longitude": -85.57484079,
--        "radiusMeters": 25
--      }
--    },
--    "latitude": 38.27088968,
--    "longitude": -85.57484079
--  }
--}'

--Load the parms into a #temp table 
DROP TABLE IF EXISTS #temp 
SELECT  JSON_VALUE(@json, '$.data.id')                  vendorID,
        JSON_VALUE(@json, '$.data.formattedAddress')    formattedAddress,
        JSON_VALUE(@json, '$.data.createdAtTime')       createdTime
INTO    #temp 

--Update stopIDs_xref depending on the processing that happened 
IF @status = 'New'
    UPDATE  stopIDs_xref
    SET     vendorId = t.vendorID,
            status = 'Processed'
    FROM    stopIDs_xref sx
            JOIN #temp t ON t.formattedAddress = sx.formattedAddress 
ELSE IF @status = 'Update'
    UPDATE  stopIDs_xref 
    SET     status = 'Processed'
    FROM    stopIDs_xref sx
            JOIN #temp t ON t.formattedAddress = sx.formattedAddress
ELSE IF @status = 'Delete'
    DELETE 
    FROM    stopIDs_xref 
    FROM    stopIDs_xref sx
            JOIN #temp t ON t.formattedAddress = sx.formattedAddress 

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật