The forum post you are referring to is from 2017. The export of contact list is now using the v2 download service that Tim was mentioning.
You don't need to manipulate the url anymore.
You can follow the other steps that Tim was mentioning in his answer.
I mean:
Step1: Use POST /api/v2/outbound/contactlists/{contactListId}/export to initiate the export of the contact list
Step 2: Use GET /api/v2/outbound/contactlists/{contactListId}/export?download=false to retrieve the download URL.
The URL will look like https://api.mypurecloud.com/api/v2/downloads/b509dea4.
Of course, with a new id/key at the end of your url. If you try this url as is, it won't work. The download url with a specific key at the end is generated following the Export Contact List API request. Note that preparing the contact list for export may take some time (several seconds) - so you may get a 404 response on the GET /api/v2/outbound/contactlists/{contactListId}/export?download=false. In case of 404, you can wait for for few seconds, send the GET request again - until you get a 200 OK which will mean the contact list is available for download
Step 3: Add ?issueRedirect=false to the download URL
Step 5: This URL will point to the AWS S3 bucket where the file is stored and will include an authorization token in the query string; do not pass your PureCloud authorization header with this request. You may use this URL for retrieving the contact list.
Can you share more information about the error response? Is there an error body with details? A 400 response means that your request was invalid in some way.
I haven't practiced Java for quite a while so I can't help much on that part (and the Spring RestTemplate).
Regarding your question above: "Now the problem I have is similar to the one they have in this post, do you know how to solve it?"
I don't have details about this ticket but reading the post, I think the problem of this person was that he was directly calling the URL obtained in Step 2 (which is a Genesys Cloud url to the download service).
If you make a request to this Genesys Cloud url, the server will answer with an HTTP redirect (303 See Other) that redirects the client to the Amazon S3 (to download the file).
In his case, as you can read in his post, it was triggering an exception.
Either because the Java HTP client framework he was using could not handle the 303 Redirect - or because the request to Amazon S3 still had an Authorization header which should not be sent (I believe it is the problem he was facing and maybe yours as well - as I could reproduce a 400 response from Amazon S3 - see below).
In the exception, the url to Amazon S3 was made available. As he wrote at the end of the post, calling the Amazon S3 url worked for him.
The difference with the steps I listed above (from Tim) is that when calling the url obtained in Step 2, you have to add the issueRedirect=false parameter.
This will tell the Genesys Cloud server to answer with a 200 OK - with the Amazon S3 url in the response body (instead of getting a 303 See Other redirect). [Step 3 and Step 4]
This will allow to get the Amazon S3 url that you can invoke [Step 5]. Do NOT set/define an Authorization header for this request which is sent to Amazon S3.
If your code is invoking the Amazon S3 url (Step 5 - url obtained on Step 4) and you have set an Authorization header, Amazon will reject it with a 400.
So check what your response body contains (in the 400 Bad Request). If it is something like what I have printed below, it is indeed a problem coming from the fact your request to Amazon S3 has an Authorization header set - which Amazon will reject.
Something like:
<?xml version="1.0" encoding="UTF-8"?>
InvalidArgument
Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified
Authorization
...
That content-type header tells you what data type the body should be parsed as. You can try converting the response body to a string as a first step if you're unsure.
When using restTemplate in java, I was passing the url as a string, and restTemplate couldn't interpret the url, so I use the URI class and pass it the string from the aws url, and I get a String!