Skip to content

Instantly share code, notes, and snippets.

@jackbravo
Created September 1, 2016 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackbravo/6a06e99ec409e2cc537afdce57c2df90 to your computer and use it in GitHub Desktop.
Save jackbravo/6a06e99ec409e2cc537afdce57c2df90 to your computer and use it in GitHub Desktop.
Registrar un usuario en drupal usando jQuery y REST, cortesía de @jmruvalcabav
var user = {
_links: {
type: {
href: 'http://192.168.100.106:81/rest/type/user/user'
}
},
name:[{'value':'user'}],
pass:[{'value':'pass'}],
status:[{'value':true}],
mail:[{'value':'example@example.com'}],
langcode:[{'value':'en'}],
roles:[{'target_id':'editor','target_type':'user_role'}],
field_publication:[{"target_id":"1","target_type":"taxonomy_term","url":"http://192.168.100.106:81/taxonomy/term/1"}]
//field_prueba:[{"value":"prueba"}]
//user_picture:[{ "target_id":"2354"}]
};
jQuery.ajax({
url: 'http://192.168.100.106:81/entity/user',
method: 'POST',
headers: {
authorization: 'Basic YWRtaW46YWRtaW4x', // user:pass base64
'Content-Type': 'application/hal+json' },
'data': JSON.stringify(user)
,
success: function (response) {
//Response
console.log("Response:");
console.log(response);
},
error: function (error){
//Error
console.log("Error:");
console.log(error);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment