His father Zhang Jiazhen had previously been a chancellor under Emperor Xuanzong and continued to serve in prominent positions after his removal in 723.
Near the end of Emperor Xuanzong's Kaiyuan era (713-741), the mayor of Jingzhao Municipality (京兆, i.e., the region of the Tang capital Chang'an), Han Chaozong (韓朝宗), who had previously been recommended by Zhang Jiazhen, stated to Emperor Xuanzong:[2] Your Imperial Majesty treated your chancellors with honor, when you commission them and when you remove them.
[2][3] During the Anshi Rebellion, Emperor Xuanzong's son and successor Emperor Suzong was, for some time, at Fengxiang (鳳翔, in modern Baoji, Shaanxi), and while there, he made Zhang Yanshang an imperial censor, initially with the rank Jiancha Yushi (監察御史), then as Dianzhong Shiyushi (殿中侍御史).
[4] Subsequently, Zhang was recalled to Chang'an to serve as chief imperial censor (御史大夫, Yushi Daifu).
Zhang disapproved of the action and did not want to be involved, and he was sent to Huainan Circuit (淮南, headquartered in modern Yangzhou, Jiangsu) to serve as its military governor as well as the prefect of its capital Yang Prefecture (揚州).
After the mourning period was over, he was recalled to serve as the military governor of Jingnan Circuit (荊南, headquartered in modern Jingzhou, Hubei), as well as the mayor of its capital, Jiangling Municipality.
)[6] In 783, there was a mutiny by his subordinate Zhang Ku (張朏), who had been posted in the mountains in the west of Chengdu in defense against Tufan.
[3] At that time, Emperor Dezong was faced with a rebellion by the general Zhu Ci and was forced to flee Chang'an.
During the times that he was at Fengtian (奉天, in modern Xianyang, Shaanxi) and then at Liang Prefecture (梁州, in modern Hanzhong, Shaanxi), until he was able to return to Chang'an after Zhu was defeated by the general Li Sheng in fall 784, Emperor Dezong relied on supplies from Xichuan Circuit, and in summer 784, he gave Zhang the honorary chancellor designation of Tong Zhongshu Menxia Pingzhangshi (同中書門下平章事).
Li, hearing that Emperor Dezong was suspecting him, offered to resign his post as military governor of Fengxiang Circuit (鳳翔, headquartered in modern Baoji, Shaanxi), in winter 786 when he was Chang'an.
Han and the general Liu Xuanzuo (劉玄佐), the military governor of Xuanwu Circuit (宣武, headquartered in modern Kaifeng, Henan), therefore, held a feast for Zhang and Li, hoping to dissolve their enmity.
Emperor Dezong recalled Li to Chang'an to serve as Zhongshu Ling and Taiwei (太尉, one of the Three Excellencies) and relieved him of all of his military duties.
Meanwhile, Zhang also drew resentment from other officials when he made major cuts into the ranks of prefectural and county officials — eliminating about 1,000 positions — hoping to use the savings in reduced salaries for military purposes, despite objections from Ma, Wei Lun (韋倫), and Bai Zhizhen (白志貞).
[3][6] By summer 787, Emperor Dezong and Tufan's chancellor Shang Jiezan (尚結贊) had negotiated a peace treaty, and the general Hun Jian, as Emperor Dezong's emissary, was set to meet with Shang at Pingliangchuan (平涼川, in modern Pingliang, Gansu).
As a result of this debacle, Zhang claimed an illness and retired, while Emperor Dezong recalled Ma to the capital and stripped him of his command.
[6] Meanwhile, Zhang's rivalry with another official — Li Shuming (李叔明) the military governor of Dongchuan Circuit (東川, headquartered in modern Mianyang, Sichuan) — which formed when they governed neighboring circuits, led Zhang to carry out some additional actions intended to bring down Li Shuming.