Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IdHTTP Post problem
#1
I am trying to post weather data to the OpenWeatherMap API server.
They use a RESTful server (API 3.0).
The documentation on this is totally incomplete.

Using a third-party program called 'ARC' and a lot of research, I discovered that in addition to adding the KEY to the URL, it is also required that *before* the HTTP Request the same KEY is send, which in this ARC program is called an 'Action', with a 'Name' and a 'value'.
In another application reference on the Internet the same name+value where added in what was called the 'Params' of this application.

The only Params I have been able to find in the IdHTTP Client is here:

IdHTTP1.Request.Authentication.Params.AddValue('appid',APIKey);

But this cannot be done because the 'Authentication' is not created.
And when I try to create it manually, I get a
[dcc32 Warning] Unit1.pas(224): W1020 Constructing instance of 'TIdAuthentication' containing abstract method 'TIdAuthentication.DoNext'

I am not even sure if this is the right location for this 'name' + 'Key'.

The OpenWeatherMap API does not do any negotiation; When the HTTP Post is not excactly correct, it just gives a '400' and disconnects.

OnAuthorisation and OnSelectAuthorisation are never called.

How am I to add these values to the HTTP Post, *before* the body containing JSON data is send?
---
Bart Kindt
CEO and Developer
SARTrack Limited
New Zealand
Reply
#2
(07-11-2019, 10:46 PM)BartKindt Wrote: I am trying to post weather data to the OpenWeatherMap API server.
They use a RESTful server (API 3.0).
The documentation on this is totally incomplete.

In what way exactly? Reading the API documentation, it looks quite complete and straight forward to me. But I see no version 3.0, only version 2.5. What part of the API exactly are you having trouble with?

(07-11-2019, 10:46 PM)BartKindt Wrote: Using a third-party program called 'ARC' and a lot of research, I discovered that in addition to adding the KEY to the URL, it is also required that *before* the HTTP Request the same KEY is send, which in this ARC program is called an 'Action', with a 'Name' and a 'value'.

I see nothing like that mentioned in the API documentation. Can you be more specific?

(07-11-2019, 10:46 PM)BartKindt Wrote: In another application reference on the Internet the same name+value where added in what was called the 'Params' of this application.

Can you provide a link to that reference?

(07-11-2019, 10:46 PM)BartKindt Wrote: The only Params I have been able to find in the IdHTTP Client is here:

IdHTTP1.Request.Authentication.Params.AddValue('appid',APIKey);

That is the completely wrong place to put API parameters. They need to go either in the query string component of the URL itself (as this weather API appears to use), or in the post body (which this weather API does not use).

(07-11-2019, 10:46 PM)BartKindt Wrote: I am not even sure if this is the right location for this 'name' + 'Key'.

It is not.

(07-11-2019, 10:46 PM)BartKindt Wrote: The OpenWeatherMap API does not do any negotiation; When the HTTP Post is not excactly correct, it just gives a '400' and disconnects.

OnAuthorisation and OnSelectAuthorisation are never called.

Because this weather API does not use HTTP authentication. You have to include your API appkey in each request. That is your authentication.

(07-11-2019, 10:46 PM)BartKindt Wrote: How am I to add these values to the HTTP Post, *before* the body containing JSON data is send?

You don't send anything before a request. Whereever you got that idea from is wrong. The API documentation is very clear on this:

https://openweathermap.org/appid

Quote:Example of using API key in API call

Description:

Please, use your API key in each API call.

We do not process API requests without the API key.

API call:

Code:
http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID={APIKEY}

Parameters:

APPID {APIKEY} is your unique API key 

Example of API call:

Code:
api.openweathermap.org/data/2.5/forecast?id=524901&APPID=1111111111

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)