Views Services ( webservice desde reporteador Y EJEMPLOS)

Utiliza el modulo  drupal de views_services en Version: superior a 7.x-1.2

TEST/DEMO = https://sima.agxproducts.com/simawebs/views/Reportes_SIMA3.json?display_id=afiliado_data&uid=23 

Para crear un nuevo webservice/api basado en una vista:

  1. Crear display tipo service
  2. configurar la vista con las variables/campos requeridos 
  3. si requiere variables de entrada configurarlas en  FILTER CRITERIA asignando las valiables dentro de cada filtro en "Filter identifier"
  4. Si el campo es obligatorio  en "EXPOSED FORM"  dejar Exposed form style:Input required  y en la variable dar campo exijido
  5. Dar permisos en SERVICES 
  6. Acceder como http://example.com/<endpoint path>/views/<view machine name>?display_id=<display_id>&varible1=xyz&variable2=abcd

<endpoint path> : Creado en estructura > services. Deben darse ltambien os permisos para acceder al servicio en el "resource" del webservice creado.
<view machine name> : verla en el url 
display_id : nombre de maquina del display  en views

 

 

Drupal Services Examples

tyler's picture

Submitted by tyler on Fri, 10/28/2011 - 09:55

Updated: 2017-05-04

Category: 

Code

Tags: 

services

planet drupal

drupal 7.x

jDrupal: Be sure to check out jDrupal for an easy to use JavaScript Library to communicate with Drupal Services.

This document describes how to read/write entities to/from Drupal using the Services module. It also covers how to handle session authentication. Let's get started...

Installation and Setup

  1. Download the Services Module
  2. Enable It
  3. Drink Dr. Pepper

Now to create a service, we'll start with the basics... go to Structure -> Services -> Add, and enter some stuff like this:

Name my_services
Endpoint title My Services
Server REST
Path to endpoint my_endpoint

Ignore the other fields for now. Click 'Save' to, you guessed it, save your new service.

Next up, we need to enable some Resources for our Service. Go to Site Structure -> Services -> List, then click 'Edit Resources' next to your Service.

Check the boxes next to each resource that you'd like to enable, save, then flush all of Drupal's caches.

Examples

Each example below includes the HTTP method (GET, POST, PUT, or DELETE) and an example URL to use. When using POST or PUT, you must send along some data, and that example data will be listed on the line after the http method and url. If there is a special Content-Type header to use, it will be mentioned after the data, otherwise just use application/json.

C.R.U.D.I. = Create, Retrieve, Update, Delete, Index

X-CSRF-Token

For all POST, PUT and DELETE requests (except for user login), you must attach a token to the header of your request. The name of the header to use is:

X-CSRF-Token

The value of the token can be retrieved here:

http://localhost/drupal-7?q=services/session/token

Content-Type

Unless otherwise noted, the Content-Type header of your request should be set to:

application/json

Session Authentication

GET: http://localhost/drupal-7/?q=services/session/token

POST: http://localhost/drupal-7/?q=my_endpoint/system/connect.json

POST: http://localhost/drupal-7/?q=my_endpoint/user/login.json
username=w5TmhqOvWF&password=4mBj5tYQu8
application/x-www-form-urlencoded
    
POST: http://localhost/drupal-7/?q=my_endpoint/user/logout.json

POST: http://localhost/drupal-7/?q=my_endpoint/user/register.json
{"name":"yFzqH7dNEv","mail":"kT3miidPAx@example.com","pass":"MSQ4JvRhZh","pass2":"MSQ4JvRhZh"}
application/x-www-form-urlencoded

User C.R.U.D.I.

POST: http://localhost/drupal-7/?q=my_endpoint/user.json
{"name":"LSAwug2XxL","mail":"soRkkjZisJ@example.com","pass":"iPpNcwnEqW","pass2":"iPpNcwnEqW"}

GET: http://localhost/drupal-7/?q=my_endpoint/user/52.json

PUT: http://localhost/drupal-7/?q=my_endpoint/user/52.json
{"uid":"52","mail":"8dGyPlGSrB@example.com","current_pass":"iPpNcwnEqW"}

DELETE: http://localhost/drupal-7/?q=my_endpoint/user/52.json

GET: http://localhost/drupal-7/?q=my_endpoint/user.json

Node C.R.U.D.I.

POST: http://localhost/drupal-7/?q=my_endpoint/node.json
{"type":"article","title":"BEVVtDcZmL","language":"und"}

GET: http://localhost/drupal-7/?q=my_endpoint/node/125.json

PUT: http://localhost/drupal-7/?q=my_endpoint/node/125.json
{"node":{"nid":"125","title":"KHrkDnudKR","language":"und"}}

DELETE: http://localhost/drupal-7/?q=my_endpoint/node/125.json

GET: http://localhost/drupal-7/?q=my_endpoint/node.json

Comment C.R.U.D.I.

POST: http://localhost/drupal-7/?q=my_endpoint/comment.json
{"subject":"S5KeJTVFED","comment_body":{"und":[{"value":"gSXNfHPxgf"}]},"nid":"126"}

GET: http://localhost/drupal-7/?q=my_endpoint/comment/30.json

PUT: http://localhost/drupal-7/?q=my_endpoint/comment/30.json
{"subject":"wULr64gdpj","comment_body":{"und":[{"value":"YhmemEQ4Cy"}]},"cid":"30"}

DELETE: http://localhost/drupal-7/?q=my_endpoint/comment/30.json

GET: http://localhost/drupal-7/?q=my_endpoint/comment.json&parameters[cid]=30

Taxonomy Vocabulary C.R.U.D.I.

POST: http://localhost/drupal-7/?q=my_endpoint/taxonomy_vocabulary.json
{"name":"WkSTeYfABe","description":"RQoHVs22yZ","machine_name":"wksteyfabe"}

GET: http://localhost/drupal-7/?q=my_endpoint/taxonomy_vocabulary/16.json

PUT: http://localhost/drupal-7/?q=my_endpoint/taxonomy_vocabulary/16.json
{"vid":"16","name":"gSXktVuVty","machine_name":"wksteyfabe"}

DELETE: http://localhost/drupal-7/?q=my_endpoint/taxonomy_vocabulary/16.json

GET: http://localhost/drupal-7/?q=my_endpoint/taxonomy_vocabulary.json&parameters[name]=WkSTeYfABe

Taxonomy Term C.R.U.D.I.

POST: http://localhost/drupal-7/?q=my_endpoint/taxonomy_term.json
{"vid":"17","name":"V8m22sqRBO"}

GET: http://localhost/drupal-7/?q=my_endpoint/taxonomy_term/13.json

PUT: http://localhost/drupal-7/?q=my_endpoint/taxonomy_term/13.json
{"vid":"17","tid":"13","name":"C5Kjy2WOxK"}

DELETE: http://localhost/drupal-7/?q=my_endpoint/taxonomy_term/13.json

GET: http://localhost/drupal-7/?q=my_endpoint/taxonomy_term.json&parameters[vid]=17&parameters[name]=V8m22sqRBO

 

 

 

INFO MAS DETALLADA Y PARA MOBILES:

 

http://www.tylerfrankenstein.com/code/android-app-with-drupal-7-services..