0

I am trying to add a location to a node using Drupal services.

This is the JSON sent to the service

{ 
   "node":{
      "type":"restaurant",
      "title":"Restaurant from JSON API",
      "field_restaurant_location ":{
         "und":{
            "locpick":{
               "user_latitude":"22.38131",
               "user_longitude":"114.168639"
            }
         }
      }
   }
}

I can not get it to save the location to the node. Any ideas ?

2

Should anyone else have this problem, the correct answer is:

{
    "node": {
        "field_restaurant_location": {
            "und": [
                {
                    "country": "us",
                    "latitude": "-26.2041",
                    "locpick": {
                        "user_latitude": "-26.2041",
                        "user_longitude": "28.0473"
                    },
                    "longitude": "28.0473"
                }
            ]
        },
        "title": "Restaurant from JSON API",
        "type": "restaurant"
    }
}
0

Try this once, I hope would work for you. Sometime "Access denied for user anonymous" error also comes, if this issue is coming then it is coming due to different reason. If it doesn't work then share the error with us.

{
    "node": {
        "type": "restaurant",
        "title": "Restaurant from JSON API",
        "field_restaurant_location ": {
            "und": [
                {
                    "locpick": {
                        "user_latitude": "22.38131",
                        "user_longitude": "114.168639"
                    }
                }
            ]
        }
    }
}
  • Thanks, but I am not trying to create an article. I am trying to create a restaurant, and I have a content type named restaurant with a title and a location. – Jens Jun 13 '14 at 0:07
  • I tried your JSON by changing the type into restaurant, but got the same result as before. A restaurant was created without a location. – Jens Jun 13 '14 at 0:08
  • I am not getting any errors – Jens Jun 13 '14 at 6:35

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.