Consume REST API - Where to use API key in URL

Hello Developers!

I am trying to get a JSON response from the http://api.weatherapi.com. It expects a GET method URL -

http://api.weatherapi.com/v1/forecast.json?key={app_Key}&q={city}

where key is the API key and q is the name of the city. I am sending the API key using site property defined as a 'text' and its value is defined in the service center. When I use this method in my application to get a response from the API, I get an error as "Invalid API key" as the value of the key is being sent as "XXXXXXXXXXXXXX" (a string in quotes, I have replaced API key characters with X).

Would someone please tell me why this is happening and what is the correct method to send the API key in the URL?

Thanks in advance!

Solution

Here you go, it is a Reactive web app, but it should help even if you are building a Traditional web app.

Regards

AJ

WeatherApiDemo.oml

Hello Saurabh,

If you have double quotes around the Effective Value in the Site Property then removing the double quotes and simply placing your key as shown below will solve the problem.

Regards,

AJ

Hello Aj

I have check the value in the Service center, but it doesn't have the double quotes. Please refer the below screen shot-


That looks good yes. Then the next thing to check is how you pass the Site property. Does this help?

If not, I will just attach an oml.

Hello Aj,

Thanks for your response. Would you please share the .oml file if the response id working? I am not able to get it only by this screen shot.

Thanks in advance!

Solution

Here you go, it is a Reactive web app, but it should help even if you are building a Traditional web app.

Regards

AJ

WeatherApiDemo.oml

Hello @Saurabh Bhandare, I was hoping the oml would have helped resolve the issue. Let me know if you have any other questions.

Regards,

AJ

Hello AJ, 

Sorry for the delayed response. The .oml file really solved the issues I was facing. Thanks for your help and time! :)

No worries, thanks for getting back. I usually follow up once just to make sure there's no open issues :). Happy to hear the issue is resolved!

Cheers,

AJ

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.