[solved] how to post a post-request lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Nicole · 2025-05-20 17:59 I am newbie in web-programming and API. After many attempts and errors I was able to do some get requests, which even work. Now I tried a post-request and I failed. Please do not wonder, it is not my code, but I asked chatGPT for it. It tried so many times and versions, - it never would work without a human. Read the comment of ChatGPT,.... it cannot even count up to three.  What does not work is the crucial thing of it: Sending the post and saving the answer. What I want to do under the line is this: https://www.openfigi.com/api/documentation This is what it wrote Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i //uses // fphttpclient, fpjson, jsonparser, sysutils, classes; function GetFigiInfo(const Ticker: string): string;var  HttpClient: TFPHTTPClient;  ResponseStream: TStringStream;  BodyStream: TStringStream;  ResponseText: string;  Json, FigiData: TJSONData;  Url, Body, API_KEY: string;begin  SetLength(Result, 0);  HttpClient := TFPHTTPClient.Create(nil);  API_KEY := 'Dein_API_Schlüssel';    Url := 'https://api.openfigi.com/v3/mapping';  Body := '{"query":[{"ticker":"' + Ticker + '","exchCode":"XNYS"}]}';    ResponseStream := TStringStream.Create('');  BodyStream := TStringStream.Create(Body);    HttpClient.AddHeader('Content-Type', 'application/json');  HttpClient.AddHeader('X-OPENFIGI-APIKEY', API_KEY);    // Richtiges Post mit 4 Parametern: URL, BodyStream (Source), ResponseStream (Dest)  HttpClient.Post(Url, BodyStream, ResponseStream);   ResponseText := ResponseStream.DataString;  Json := GetJSON(ResponseText);  FigiData := Json.FindPath('data');  if Assigned(FigiData) then    Result := FigiData.AsJSON  else    Result := 'Keine Daten gefunden.';    ResponseStream.Free;  BodyStream.Free;  HttpClient.Free;end; ---------------------------------------------------------------------- bytebites · 2025-05-20 19:54 See working example here https://forum.lazarus.freepascal.org/index.php?topic=33564.0 ---------------------------------------------------------------------- Remy Lebeau · 2025-05-20 19:55 Quote from: Nicole on May 20, 2025, 07:59:58 pmWhat does not work is the crucial thing of it: Sending the post and saving the answer. The JSON you are sending is completely wrong for the URL you are sending it to.  Apparently you did not read the documentation you linked to. You are sending a single JSON object containing a "query" field to the '/v3/mapping' URL, but that JSON is meant for the '/v3/search' URL instead.  The '/v3/mapping' URL wants an array of JSON objects, each containing "idType", "idValue", etc fields. ---------------------------------------------------------------------- Nicole · 2025-05-24 10:12 Thank you for the answers! Here is my working example, call it e.g. by "s:=GetFigiInfo('SAP');" Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function GetFigiInfo(const Ticker: string): string;const  API_URL = 'https://api.openfigi.com/v2/mapping';  API_KEY = 'xxxxxxxxxxxxxxx';  // please get a free key by visiting the domain var  HttpClient: TFPHttpClient;  Response: TStringStream;  RequestBody: TStringStream;  JsonRequest: string;  Exchange: string;begin  Result := '';  JsonRequest := '[{"idType":"TICKER","idValue":"' + Ticker + '"}]';    HttpClient := TFPHttpClient.Create(nil);  Response := TStringStream.Create('');  RequestBody := TStringStream.Create(JsonRequest);  try    // Header setzen    HttpClient.AddHeader('Content-Type', 'application/json; charset=UTF-8');    HttpClient.AddHeader('X-OPENFIGI-APIKEY', API_KEY);     // JSON-Body zuweisen und POST senden    HttpClient.RequestBody := RequestBody;    HttpClient.Post(API_URL, Response);     // Antwort als String zurückgeben    Result := Response.DataString;  finally    Response.Free;    RequestBody.Free;  HttpClient.Free;  end;end;