We had [to go [to get a book]]].
Preliminary point: most speakers treat stative "have" as a lexical verb, but some treat it as an auxiliary.
The sentence consists of a main clause (the sentence as a whole) and two embedded subordinate clauses, as bracketed.
"Have" is a catenative verb and the subordinate clause "to go to get a book" is its complement.
The second subordinate clause, "to get a book", is a purpose adjunct in clause structure. "A book" is object of "get".