0

I have a Drupal 8 site with the following modules:

  • HAL.
  • HTTP Basic Authentication.
  • REST UI.
  • RESTful Web Services.
  • Serialization.

Using the REST UI module, I configured it as follows.

Settings for resource User

Granularity - Resource

Methods - GET - POST - PATCH

Accepted request formats - json

Authentication providers - basic_auth - cookie

I created an IOS & Android web-view app. I am using the Firebase module to send 'Push Notifications' to registered users on the website on specific events, such as Send a push notification to the 'node author' whenever his node is updated.

I know I have to pass a unique token of the mobile device used by the logged in user and store it on my Drupal site. for that, I have created the field_user_push_token text field on the user profile page in order to store the token received from the mobile device of the user.

How can I transfer the token from the mobile device to the field_user_push_token field?

I believe I should use the PATCH method, but I don't know how.

Am I on the right track by using the RESTful Web Services, or is there a better method?

UPDATE #1:

I am the web developer of the website but not the mobile developer, so I asked a mobile developer (Not familiar with Drupal) to create the 'web-view' apps for me... He told me to setup an API for him so he can access the website and he will generate the token and send it to my Drupal website through the provided API...

My skills towards Restful API are very limited so by following some tutorial I have setup the Restful web service API on my website but:

What information I have to give him in order to access my website from the created 'web-view' app ?

is it only https://example.com/user/{user}?_format=json or I am missing something here ?

I am a bit confused...

closed as too broad by kiamlaluno Jul 9 at 8:36

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1

Elie Masaad, You can use PATCH method like this Drupal 8 Android app at https://github.com/onedrupal/One-Drupal-Android.

PATCH related android source code using OkHttpClient https://github.com/onedrupal/One-Drupal-Android/blob/master/app/src/main/java/com/technikh/onedrupal/activities/ActivityPost.java#L637

request = new Request.Builder()
                        .header("Content-Type", "application/json")
                        .url(url)
                        .patch(api_body)
                        .build();
OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(20, TimeUnit.SECONDS)
                .writeTimeout(20, TimeUnit.SECONDS)
                .readTimeout(20, TimeUnit.SECONDS)
                .addInterceptor(new AddCookiesInterceptor())
                .build();

AddCookiesInterceptor at https://github.com/onedrupal/One-Drupal-Android/blob/master/app/src/main/java/com/technikh/onedrupal/network/AddCookiesInterceptor.java

You can define your REST endpoint for Android Retrofit at https://github.com/onedrupal/One-Drupal-Android/blob/master/app/src/main/java/com/technikh/onedrupal/network/GetSiteDataService.java#L31 like

@GET("/node/{editNid}?_format=json")
    Call<ModelNodeType> getNode(@Path("editNid") String nid);
  • thank you for the answer, your app looks promising and sure will use it on a different project currently under development! However, my case here is different since my current project requires app for both IOS and android which they are already built and ready to use (web-view apps)... I need to find the solution for How can I transfer the token from the mobile device to the field_user_push_token field available on user profile page ? using Restful web service API module and not One_API module... Correct me please if I am wrong ! – Elie Masaad Mar 29 at 16:31
  • 1
    Elie Masaad, one_api module is just a configuration around core REST APIs. Download & enable Rest UI module at drupal.org/project/restui. Then you will be able to enable user PATCH endpoint. Use something like POSTMAN getpostman.com to update user field_user_push_token field using PATCH endpoint. If you are able to successfully use POSTMAN to update the field_user_push_token field then you can do it from iOs or Android(OkHttpClient) code. – TechNikh Mar 30 at 19:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.