We are using the HERE api to retrieve geolocations. We had the API Key hardcoded, and yes, of course this is wrong. We want instead use a Named Credential.
Using below endpoint works:
String address = ...;
String apiKey = 'VALUE_API_Key';
...
req.setEndpoint(https://geocode.search.hereapi.com/v1/geocode?q= + address + '&apiKey=' + apiKey);
...
I rewrote this to the following:
String namedCredential = 'nmspc__hereapi';
String url = 'https://geocode.search.hereapi.com/v1/geocode?q=';
String address = ...;
...
req.setEndpoint('callout:' + namedCredential + '/v1/geocode?q=' + address + '&apiKey={!$Credential.HEREAPI.HEREAPIKey}');
...
I stored the api key in the principle of the external credential called HEREAPI and the parameter itself is called HEREAPIKey. I set Allow Formulas in HTTP Header to true.
I receive error: Illegal character in opaque part at index X: callout:msf__hereapi/v1/geocode?q=Address&apiKey={!$Credential.HEREAPI.HEREAPIKey}
I am clearly doing something wrong to set the endpoint. But I can't seem to find the right examples.
Any help on how to set the correct endpoint would be greatly appreciated! Thanks.