Delphi - Oauth 1.0 Authentication - Woocommerce Api Rest

Asked

Viewed 1,687 times

1

Hello, I’m trying to make a 'POST' in the Woocommerce Rest API using Delphi. I’ve done several tests using a lib. which I downloaded in http://sourceforge.net/projects/oauthdelphi/ but without success. So, as there is now the 'Restclient' palette, I tried with 'Trestclient', 'Trestrequest', 'Toauth1authenticator' and at last I only inform 'consumer_key' and 'consumer_secret', but it passes the information [oauth_consumer_key, oauth_timestamp, oauth_nonce, oauth_signature, and oauth_signature_method] in the header, but must be passed as query string.

The Oauth Parameters must be Added as query string Parameters and not included in the Authorization header. This is because there is no Reliable cross-Platform way to get the raw request headers in Wordpress.

In the demo 'REST-Library :: Demos', there is no example of the Oauth 1.0a (One Leg) stream. Anyway, I would like to know how to send the parameters as query string, using the components, or if there is another way to send this request to the API.

OAuth1Authenticator1.ConsumerKey := 'ck_f972e91046ea920e8b7c8141e1df516d7eea47b8';
OAuth1Authenticator1.ConsumerSecret := 'cs_adc97ab54caffe1c06b7f8dbb0c07de0adaa3f92';
OAuth1Authenticator1.SigningClassName := 'TOAuth1SignatureMethod_HMAC_SHA1';
OAuth1Authenticator1.CallbackEndpoint := '';
//oauth1.Authenticate(RESTRequest1);

RESTClient1.Authenticator := OAuth1Authenticator1;

RESTClient1.BaseURL := 'http://localhost/wordpress/wc-api/v2';

RESTRequest1.Resource := 'products';

RESTRequest1.Method := TRESTRequestMethod.rmPOST;
RESTRequest1.Params.AddItem('title', 'produto teste', TRESTRequestParameterKind.pkGETorPOST);

RESTRequest1.Execute;

if assigned(RESTResponse1.JSONValue) then
begin
  Memo1.Lines.Text := TJson.Format(RESTResponse1.JSONValue)
end
else
begin
  Memo1.Lines.Add(RESTResponse1.Content);
end;
  • Hello Will! Could you put your code here to show us what you’ve tried to do.

  • I edited the question and put the code. In fact, I have tried several times with Postman and also can not run a POST, already with the 'Woocommerce-REST-API-Client-Library-master' PHP works.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.