Bulk Selection of Observations to Add to a Project

here’s a version of this using Windows batch files:

  1. open Notepad or some other plain text editor
  2. copy and paste the following lines into your text editor:
    @echo off
    set jwt=redacted
    set project_id=63299
    set observation_id=151385912 151363952 151363946
    for %%o in (%observation_id%) do (
      echo Adding observation %%o to project %project_id%
      curl "https://api.inaturalist.org/v1/projects/%project_id%/add" -X "POST" -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: %jwt%" -d "{\"observation_id\": %%o}"
      timeout 1
    )
    pause
    
  3. in lines 2-4 above, replace the values with values appropriate for your use case. note that you can specify multiple observation ids by setting observation_id to a space-separated list of observation ids. (if jwt value above was valid, the code above would attempt to add 3 observations – 151385912, 151363952, and 151363946 – to project 63299.)
  4. save the file with a .bat extension. (in Notepad, you may have to explicitly set the file type to All Files in order to add a .bat extension to your filename properly.)
  5. find your .bat file, and double-click it to execute it.

EDIT: in case you need to remove observations in bulk, here are the lines you would use in step 2 above:

@echo off
set jwt=redacted
set project_id=63299
set observation_id=151385912 151363952 151363946
for %%o in (%observation_id%) do (
  echo Removing observation %%o from project %project_id%
  curl "https://api.inaturalist.org/v1/projects/%project_id%/remove" -X "DELETE" -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: %jwt%" -d "{\"observation_id\": %%o}"
  timeout 1
)
pause

also, if you want to skip the batch file and run directly in the command prompt, you can use this code to add:

set jwt=redacted
set project_id=63299
set observation_id=151385912 151363952 151363946
for %o in (%observation_id%) do ( echo Adding observation %o to project %project_id% & curl "https://api.inaturalist.org/v1/projects/%project_id%/add" -X "POST" -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: %jwt%" -d "{\"observation_id\": %o}" & timeout 1 )
pause

and this code to remove:

set jwt=redacted
set project_id=63299
set observation_id=151385912 151363952 151363946
for %o in (%observation_id%) do ( echo Removing observation %o from project %project_id% & curl "https://api.inaturalist.org/v1/projects/%project_id%/remove" -X "DELETE" -H "Content-Type: application/json" -H "Accept: application/json" -H "Authorization: %jwt%" -d "{\"observation_id\": %o}" & timeout 1 )
pause
2 Likes