You are not logged in.
Hi,
for my project that uses webservice (based on mORMot) I will have to create users in Wordpress with the same account ( username,pwd,email, etc)  and maybe later to reading/writing WooCommerce data. Therefore  I created a small library to accomplish it.
I tried to use ORM classes for the work with Wordpress records.
The reading looks like this
type 
TWPRESTAPI1_0_3LEGS = class(TWPRESTAPI)       // my class for dealing with Wordpress REST API include providing authentication
...
TSQLWPClient = class(TSQLHttpClientWinHTTP)
...
TSQLRESTAPIUser = class(TSQLRecord)
  protected
    fusername: RawUTF8;
    fname: RawUTF8;
    ffirst_name: RawUTF8;
    fnickname: RawUTF8;
    fslug: RawUTF8;
...
var
     fWP: TWPRESTAPI1_0_3LEGS ;  
     fWPClient : TSQLWPClient;
     fWPUser : TSQLRESTAPIUser;
procedure ReadWPUsers;
begin    
    fWP := TWPRESTAPI1_0_3LEGS.create('WPRestAPI.json'); // WPRestAPI.json - the file containing TSQLRecord that stores Wordpress server, consumer key, secret consumer key etc. 
    fWP.Connect;
    fWPClient := TSQLWPClient(fWP.getWAPIClient('users', '{"search":"*eva*","orderby":"username}'));   //'users' is route of WP REST API and '{"search":...'  is filter
 
    fWPUser := TSQLRESTAPIUser.CreateAndFillPrepare(fWPClient,'',[]);
end;the updating like this:
procedure UpdateWPUser;
begin
  if assigned( fWPUser) then
  begin
    fWPUser.FillRewind;
    while fWPUser.FillOne do
    begin
      if fWPUser.username=EditWPUsername.text then
      begin
        fWPUser.description := EditWPdescription.text;
        fWPClient.Update(fWPUser);
      end;
    end ;
  end;
end;I had to only take care of the authentication of the requests, everything else was pretty simple thanks mormot.
Offline
hereby is source https://github.com/Eva-F/mormot-WP-REST-API
maybe it helps somebody
a little remark:
I am not good in the writing of commentaries neither in my native language let alone in English.
I know only a small fraction of mormot, so some part of my code could use routines of mormot better and more effectively
Offline
Thanks for sharing!
Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.
Offline
Thanks for the warning, I will take look into - in this case I think that in SynCommons is a suitable subroutine for this purpose, but I could not find it
Offline
I did not understand the purpose of this function, and its use case...
I will try to explain my idea:
I have intended  to call the CallbackGet function that uses open array of TVarRec as a parameter.
function TSQLRestClientURI.CallBackGet(const aMethodName: RawUTF8;
  const aNameValueParameters: array of const; ...): integer;
 Rather then explicitly enumerate all name, value pairs I would prefer to add them gradually one by one based on the actual authentication stage. Therefore each NameValue pair is copied into a FParameters array
    fParameters: array of TVarRec;and afterwards passed as an aNameValueParameters.
fOauthClient.CallBackGet('request', fParameters, lResponse)I have fixed the unsatisfactory releasing of fParameters and there are no memory leaks now.
Further I have discovered a bug in OAuth1 plugin and when I have checked it on Github, I have found out that there is a new version of Oauth1 plugin available and that this new version changed the way the signature is created at the third leg of authetication. I have also added the support for OAuth1 plugin version 0.2.1 into source code.
Offline
You could use a TDocVariantData to store the array and convert it to an array of const.
ok, thanks, I did it by your recommended way.
Offline
Hi EvaF,
i'm testing your mormot-WP-REST-API.
I try to follow your instruction on readme, installed the plugin (but some version of plugin is updated), generate the key, edit json configuration file.
I have no response when i try to "get WP users".
I get error 404: rest_no_route if i try to create new user.
I read well woocommerce customers with "get Woo Customers".
I get error 404: woocommerce_api_no_route if i try to create new customer.
I think that i mistake something in the configuration file or in wordpress configuration.
Can you help me to understand?
thanks
Offline
I will check all new versions and after that let you know...
E.
Offline
thanks a lot!
Offline
I checked only WordpressREST ( sorry - a few time). I have installed new version (Oauth 0.3.0, Wordpress 4.7 +  Mormot Nigth Build -mORMot_and_Open_Source_friends_2016-12-21_193435_df194baa76) and made a couple of the small changes in WordpressREST sources.
The adding, updating and listing Wordpress users works now. 
About the Error 404: rest_no_route
Please check your Wordpress endpoint address 
=[WP-REST-API-Url] - http[https]://[your-WP-server]/wp-json/ in WPRESTAPI.json
and 
=[WOO-REST-API-Url] - http[https]://[your-WP-server]/wc-api/[Woocommerce API version]/ in WooRESTAPI.JSON      
f.e.
http://somewordpress.blabla.com/wc-api/v2/Last edited by EvaF (2016-12-23 10:31:49)
Offline
Hi,
I download mormorò nigth build and your fresh code from guthub bit now i have anche access violation when i try to get user or customer.
Thanks
Offline
Hi,
I forgot to comment some debug statements - sorry. The fixed version of WPRESTAPI.pas file is on git.
Offline