B4Him 0 Posted January 9 (edited) Accessing APIs is new territory for me. I am trying to access an API using TNetHttpClient component. The curl example provided is: curl --request GET 'https://api.samsara.com/fleet/vehicles/stats' \ -d types='engineStates' \ -d decorations='gps' \ --header 'Authorization: Bearer TOKEN' \ -G I have been unsuccessful at using various settings of TNetHttpClient to get the authorization. I have the proper token but everything I try, I get the results "message":"invalid token" followed by the request id. My latest attempt is below but same results. Can anyone advice and perhaps provide sample code of how to accomplish this? Thank you in advance. var Params: TStringList; begin Params :=TStringList.Create; Params.Add('types = engineStates'); Params.Add('decorations=gps'); http1.CustHeaders.Add('Authorization', '<My Token>'); //<My Token replaced with actual token memo2.Lines.Text :=http1.Post('https://api.samsara.com/fleet/vehicles/stats', Params).ContentAsString; end; Edited January 9 by B4Him Share this post Link to post
stijnsanders 38 Posted January 9 (edited) Don't forget the 'Bearer' bit here: http1.CustHeaders.Add('Authorization', 'Bearer '+MyToken); (as for the HTTP requests, I've been using MSXML2_TLB.pas for a long time (see an example here), and lately WinHTTP directly, but I don't have open-sourced that code yet.) Edited January 9 by stijnsanders Share this post Link to post