AnsweredAssumed Answered

How to send a Post request to Wordpress-Rest-API using MBS?

Question asked by habitare on Oct 31, 2018
Latest reply on Oct 31, 2018 by monkeybreadsoftware

Hi,

I struggle a bit to get a post curl call against the Wordpress API running. I googled a lot and found nearly no real code samples to do so. To get information "out" of Wordpress is quite easy, but where do I make a mistake too get information in? And no, I do not want to buy a SyncServer to do this task....

 

As long as I just call (GET) info on posts, no problem. But this PUT-call dies not work. Error:

 

{"code":"rest_no_route","message":"Es wurde keine Route gefunden, die mit der URL und der Request-Methode identisch ist.","data":{"status":404}}

 

Here is my sample code I tried so far.

 

#

#  New CURL-Session

Variable setzen [ $curl ; Wert: MBS("CURL.New") ]

#

#  URL for Rest-Api

Variable setzen [ $URL ; Wert: Wordpress::rf_URL & Wenn (  MusterAnzahl ( Wordpress::rf_URL  ; "/posts/" ) = 0  ; "/posts/"  ; "" ) ]

#  leads to: www.myserver.de/wp-json/wp/v2/posts/

 

Variable setzen [ $r ; Wert: MBS("CURL.SetOptionURL" ; $curl ; $URL ) ]

Variable setzen [ $r ; Wert: MBS("CURL.SetOptionUpload"; $curl; 1) ]

Variable setzen [ $r ; Wert: MBS("CURL.SetOptionPut"; $curl; 1 ) ]

#

#  Set input for a new post

Variable setzen [ $WP_Post_Daten ; Wert: "title=" & Wordpress::title & "&date=" & Wordpress::date & "$author=" & Wordpress::author & "&=author" & Wordpress::author & "&=featured_media" & Wordpress::status & "&=featured_media" & Wordpress::featured_media & "&=comment_status" & Wordpress::commen… ]

Variable setzen [ $r ; Wert: MBS("CURL.SetInputText"; $curl; $WP_Post_Daten ) ]

#

#  Login-Data

Variable setzen [ $r ; Wert: MBS("CURL.SetOptionUsername"; $curl; Wordpress::rf_Benutzer ) ]

Variable setzen [ $r ; Wert: MBS("CURL.SetOptionPassword"; $curl; Wordpress::application_password__encrypted ) ]

Variable setzen [ $r ; Wert: MBS( "CURL.SetOptionHTTPAuth"; $curl; 15 ) ]

#

#  SSL

Variable setzen [ $r ; Wert: MBS( "CURL.SetOptionProxySSLVerifyHost"; $curl; Wenn ( IstLeer ( Wordpress::rf_Status_SSL ) ; 0 ; 1 ) ) ]

Variable setzen [ $r ; Wert: MBS( "CURL.SetOptionProxySSLVerifyPeer"; $curl; 0) ]

#

#  Abfrage ausführen

Variable setzen [ $error ; Wert: MBS ( "CURL.perform" ; $curl ) ]

#

#  Cleaup

Variable setzen [ $r ; Wert: MBS ( "CURL.Cleanup" ) ]

 

Any ideas to get a starting point?

Kind regards, Martin 

Outcomes