How to add special characters in Target Endpoint URL?

Not applicable

I'm looking to use https://newsapi.org/v1/articles?source=techcrunch&sortBy=top as my Target Endpoint and use Verify API Key Policy on target request flow to validate the apiKey on newsapi. But I'm not able to use the mentioned URL as target endpoint URL. I get invalid XML error. Any reference to how this can be corrected would be of help.

0 13 1,334
13 REPLIES 13

Not applicable

Hi ,

Please use url encoder present here to encode the url after the query string

http://meyerweb.com/eric/tools/dencoder/

https://newsapi.org/v1/articles?source%3Dtechcrunch%26sortBy%3Dtop

This encoded url will work.

Thanks Tamilarasan. It allows to save the proxy config without any error. But it doesn't solve the purpose. It doesn't construct the url as intended while hitting the service.

Hi ,

I'm getting this error

{ "status": "error", "message": "Your API key is missing. Append this to the URL with the apiKey param, or populate the x-api-key HTTP header." }
I guess you need to pass API key

I did append %26apiKey%3DCDE..... I still got the same API Key missing error.

having just https://newsapi.org/v1/articles?source=techcrunch as target endpoint url and passing the remaining from client request works though. So I think the problem is with '&' and the url encoding we try for '&' isn't working as expected.

Hi ,

Yes encoded url prevents the xml error but doesn't server the purpose

Do we have a way to embed query parameters in separate tags?

Hi @Loganathan Murugesan

Welcome to the community !!

The end point you provided looks good. The "?" and "&" are for the query parameters that works as Filters to get the appropriate result set. When I ran GET on

https://newsapi.org/v1/articles?source=techcrunch&sortBy=top

the api forced me to pass the APIKey with the following response

{
  "status": "error",
  "message": "Your API key is missing. Append this to the URL with the apiKey param, or populate the x-api-key HTTP header."
}

So I activated an account with newsapi.org which provided me an APIKey. I included that as another query param

https://newsapi.org/v1/articles?source=techcrunch&sortBy=top&apiKey=7c0b.

I got a valid response from the service

I then created a proxy in Apigee Edge with the target URL as above. When I made the call to the proxy, it worked.

Below is the TargetEndpoint code

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request/>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://newsapi.org/v1/articles?source=techcrunch&sortBy=top&apiKey=7c0b....</URL>
    </HTTPTargetConnection>
</TargetEndpoint>

This is a straightforward proxy. Let me know if you have any questions.

More info on the newsapi service available here

NOTE: I have purposely masked the APIKey as "7c0b...."

capture.jpg

Hi Sai Saran,

I got the same xml error mentioned by loganathan when i used this endpoint

https://newsapi.org/v1/articles?source=techcrunch&sortBy=top

Hi Sai Saran,

I purposely didn't use APIKey in the target endpoint, as I wanted it to be passed through. I wonder how you are not getting error using & in the url. It shows up invalid XML error and refuses to save the proxy configuration.

Hi @Loganathan Murugesan - are you using Apigee Edge Cloud or On prem version ? If on prem, which version. More info on the error like the screenshot or any other info will help us resolve the issue. The screenshot you shared earlier doesnt open

Hi Loganathan,

Did you try the url provided by me in above post . I hope it will work

Thanks Tamilarasan. It allows to save the proxy config without any error. But it doesn't solve the purpose. It doesn't construct the url as intended while hitting the service.