He studied canon and civil law in the University of Pisa and became canon of the cathedral chapter of Florence. Later he was made relator of the Sacred Congregation of good government in the pontificate of Pope Clement IX. Then he was appointed referendary of the Tribunals of the Apostolic Signature of Justice and of Grace and governor of Faenza (later of Spoleto and vice-legate in Ferrara). He was ordained priest on 8 September 1675.
He was elected titular Latin Archbishop of Corinth on 9 September 1675. On 20 September 1675 was appointed Apostolic nuncio in Poland. Martelli obtained the title of secretary in the Roman Curia by Pope Innocent XI. On 21 July 1698 he was promoted to the titular patriarchate of Jerusalem.