Scripting Reminders to Todoist

I have the following script, which is failing on the line “set theName to name of reminderObj” with an error of:

In the test case, the Reminder List “Shopping” has two items in it. The first item processes just fine, but the second one fails in about 90% of the cases. Occasionally it processes both items. I’m stumped and hoping one of the smart people here can tell me what I’m not seeing.


set todoistToken to "mytodoisttoken"
tell application "Reminders"
	log (count of (reminders in list "Shopping" whose completed is false)) as string
	if (count of (reminders in list "Shopping" whose completed is false)) > 0 then
		set theReminders to (reminders in list "Shopping" whose completed is false)
		repeat with j from 1 to (count of theReminders)
			set reminderObj to item j of theReminders
			set theName to name of reminderObj
			set thePriority to "4"
			set plainText to "Entered via Reminders"
			set newItem to do shell script "curl -X POST -d 'content=" & theName & "' -d 'token=" & todoistToken & "'  -d 'priority=" & thePriority & "' -d 'date_string=today' https://todoist.com/API/additem -d 'note=" & plainText & "'"
		end repeat
		delete (every reminder in list "Shopping" whose completed is false)
		
	end if
end tell