February 14, 2019 at 08:57 #34803
In the last days I really struggled to figure out how to use the Remote API to get and sync points from an Android app to a shop which is using the myCred plugin.
Even though now I see that the documentation is pretty straight forward, this was my first WP experience, but I didn’t imagine that it will take me so much time to make it work.
So for all those that want to use the Remote API functions from non WP shops here are the steps that I took:
(please note, that my app was intended only for a small prototype which I was trying out, I would advise to use a server with proper implementation for live versions)
1. Make sure the plugin is active (as stated in the official documentation)
2. Make sure you have the “Allow remote access” active (In the plugin Management settings)
3. Make sure you are using the correct API key
4. Make sure you are using the correct Incoming URI – this can be tested with a simple request in the browser – it returns 404 Not Found if it’s wrong otherwise you will get an empty 200 OK response
5. Make sure you are building the token correctly md5( $host . $action . $secret_key ) = hostactionsecret_key (simply concatenate all the properties mentioned in the documentation – because I don’t know PHP i thought that “.” or ” . ” is needed to build the hash correctly)
6. Make sure you provide all properties as described in the documentation
Now the fun part – I used Postman for testing the requests and here is the raw result of how a GET request for the points should look like:
POST /api-dev/ HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
Accept-Encoding: gzip, deflate
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Date: Thu, 20 Sep 2018 10:04:42 GMT
Expires: Mon, 25 Dec 2017 00:00:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Last-Modified: Thu, 20 Sep 2018 10:04:43 GMT
Other observations and things that confused me:
– in my case the API returned 200 OK for all requests even though I tried with wrong token or wrong data in the body (even empty body)
– what I mostly did wrong was that I didn’t formatted the body correctly according to the x-www-form-urlencoded format – and because the APi didn’t complain, well it was hard to figure it out
I added the RAW data of the request because this is actually what I was looking for, I searched through the whole forum and I mostly found only PHP examples which didn’t help me so much in determining what I was doing wrong.
The request in android I made using Retrofit2 but didn’t do anything special there, except making sure that the requests are coming out as described above.
In the hope that my post will help someone, don’t be discouraged the Remote APi actually works and not only for WP to WP shop communication.
Best of luck!
You must be logged in to reply to this topic.