I am using Portal REST API to add a bunch of secure map services to Portal (10.4.1). Right after those services added, their portal links works fine. After a while, clicking the same link would get an error page saying something like portal can't work on this content item (502 Bad Gateway). When I manually enter the credential on the Edit page, the same link would work again. And then the error occurred again.
My guess is Portal doesn't seem able to save the specified credential with the new items so the link failed when a token expires. In the REST API reference, there is no specific parameter to get Portal to save or not to save credential.