Home Forums General Issues Creating user through REST API & ACF


Creating user through REST API & ACF

  • I use the following Javascript code to create WordPress users through REST API:

    var retObject = {
        endPoint: '/wp/v2/users', 
        httpCode: 0,
        userList: []
      var myRoot = ''  
      var ret = initJWTAuthentication(myRoot);
      if (ret.httpCode != 200){
        retObject.endPoint = ret.endPoint;
        retObject.httpCode = ret.httpCode;
        return retObject;
        var queryParams = '? Rogers&first_name=Paul&last_name=Rogers&[email protected]&password=1234567';
      // Set REST API invocation parameters (WP USERS)
      options = {
            'method': 'POST',
            'followRedirects' : false,
            'muteHttpExceptions': true,
            'headers' : {'Authorization' : 'Bearer ' + ret.token}
        var response = UrlFetchApp.fetch(myRoot + retObject.endPoint + queryParams, options);
        var data = response.getContentText();
        var headers = response.getAllHeaders();
        retObject.httpCode = response.getResponseCode();
        var user = JSON.parse(data);

    This works fine and created user data is returned. Now, the question:
    Returned data upon creation includes a custom field (theClass), which looks like this, given the above code: user.acf.theClass
    To populate this custom field, do I need to issue a secondary REST POST to update the user’s custom field, or is there a way to instruct REST API to include this custom data, hence using only one call to allow user creation including custom field?

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.