'Jenkins API - Add credentials

I am adding credentials to my jenkins server via the REST API. When I try to use them it does not work. When I copy the token-hash from the credentials.xml file and decode it like here, I get the token I sent via the API but with additional spacing before the token and a linebreak afterwards. How can I remove that?

Saved via the GUI:

q4nL6VYHNy7PoyfKGj7z

Sent via the api:

        q4nL6VYHNy7PoyfKGj7z
    

This is the XML I send to the server

<io.jenkins.plugins.gitlabserverconfig.credentials.PersonalAccessTokenImpl plugin="[email protected]">
    <scope>GLOBAL</scope>
    <id>name</id>
    <description>description</description>
    <token>secret-token</token>
</io.jenkins.plugins.gitlabserverconfig.credentials.PersonalAccessTokenImpl>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source