0

I got my endpoint setup and I'm able to to do a get request to return a bunch of nodes. But I'm having issues doing a POST to create a new node.

I see that I would first need to do a user login post as seen in other tutorials. I tried doing that with the following settings in postman, but I'm getting a blank response. What could I be doing wrong? I've enable user resources as seen below also.

enter image description here

enter image description here

  • i'm posting my username and password. I'm expecting a session id response so I can use this ID to add to my 2nd POST header in order to create my node. – Patoshi パトシ Oct 1 '17 at 8:50
  • Possible duplicate of User login REST format – No Sssweat Oct 1 '17 at 9:13
  • 1
    Maybe a duplicate, but there is a distinct way of doing so with Drupal 7 Services that this might be its own distinct answer if there isn't a Drupal 7 Services question/answer out there already. That said, I don't think this question has the relevant and specific information about the Services module configuration (despite the images) to answer appropriately. – mradcliffe Oct 1 '17 at 15:54
1

In that petition you are calling the path user.login, but in services is user/login, with a slash.

Also, maybe you are not preceding the path with the base name of your api (normally is /api). So the url should be /api/user/login. You can see the path in 'Edit' tab, in 'Path to endpoint' field. enter image description here

I recommend you the module services tools which gives you a page where you can see the urls of the endpoints. This module contains a submodule called services_definitions, enable it to have this page available.Definitions tab

Example user login definition

  • Thanks! that works, but why is my output html, shouldn't it be json format with the session id? prntscr.com/grvtqw – Patoshi パトシ Oct 1 '17 at 12:22
  • In services, api endpoint urls must have a prefix. For example, instead of /user/login it must be /api/user/login. You need add that prefix to the URL. You can see what prefix you must use in your configuration ( see the first screenshot of ky answer, that is the Page, and te field 'path to endpoint' it's the prefix. – mistermoper Oct 1 '17 at 15:06
  • If you're getting HTML, chances are a contrib module is hooking into the login process and interferring with the Services module. Here's a perfect example of a contrib module that unkowingly does just that: drupal.org/node/2167987 – tyler.frankenstein Oct 2 '17 at 16:03
  • Sorry if I explained uncorrectly. In the screenshot's request is just calling the user/login page from Drupal which is user login form, is not calling the api endpoint. See my previous response to know how to make the request to the correct endpoint. – mistermoper Oct 4 '17 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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