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:

  1. Open FireFox Poster
  2. Enter the URL: http://www.example.com/?q=services/session/token
  3. Click the GET button
  4. Copy the token

Add the Token to the Header

  1. In FireFox Poster, click the Headers tab
  2. Enter the Name: X-CSRF-Token
  3. Enter the Value: [paste-your-token-here]
  4. Click the Add/Change button

Make the Service Request

  1. Enter the Service Resource URL, for example: http://www.example.com/?q=my_endpoint_path/node.json
  2. Click the Parameters tab
  3. Enter a name: type
  4. Enter a value: article
  5. Click add/change
  6. Enter a name: title
  7. Enter a value: Hello World
  8. Click the "Content to Send" tab
  9. Click the "Body from Parameters" button
  10. 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

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!!

Add new comment