Moved API JSON creation to its own function.