Drupal - Services CSRF Token with FireFox Poster
Category:
With the introduction of the CSRF Token a few months ago, service calls in Drupal need to pass along that token for certain resources. Using FireFox Poster, we can pass along this token to easily test and debug our services.
Here's an example to pass along the token for a simple article node creation.
Retrieve the Token and Copy it
Go to the following URL in your browser and copy the token:
http://www.example.com/?q=services/session/token
Or grab it from inside FireFox Poster:
- Open FireFox Poster
- Enter the URL: http://www.example.com/?q=services/session/token
- Click the GET button
- Copy the token
Add the Token to the Header
- In FireFox Poster, click the Headers tab
- Enter the Name: X-CSRF-Token
- Enter the Value: [paste-your-token-here]
- Click the Add/Change button
Make the Service Request
- Enter the Service Resource URL, for example: http://www.example.com/?q=my_endpoint_path/node.json
- Click the Parameters tab
- Enter a name: type
- Enter a value: article
- Click add/change
- Enter a name: title
- Enter a value: Hello World
- Click the "Content to Send" tab
- Click the "Body from Parameters" button
- Click the POST button
That's it!
That's all we need to do to attach the CSRF token to our requests that need it.
Comments
Alina Guerrero (not verified)
Wed, 02/04/2015 - 18:42
Permalink
Thank you very much I tried
Thank you very much I tried to create a node with poster for more than 8 hours and your tutorial was the only one than worked. No one else mentioned that the URL should include /node.json intead of just /node. Thanks a lot!!