POST members Howto

Hi there exciting folks,

as a newbe I’m not sure, if this is the right forum.

I need to create a new member/adherent via REST. eg.

curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'DOLAPIKEY: xxxxxxxxx' -d '{"firstname":"Erika","lastname": "Musternann","statut":1}' 'https://test.home64.de/api/index.php/members'

but constantly getting this result:

{
  "error": {
    "code": 400,
    "message": "Bad Request: Invalid value specified for `request_data`"
  },
  "debug": {
    "source": "Validator.php:718 at validate stage",
    "stages": {
      "success": [
        "get",
        "route",
        "negotiate",
        "authenticate"
      ],
      "failure": [
        "validate",
        "message"
      ]
    }
  }
}

I tried statut as well as status (and both). No Hints in the Logs.

My PHP skills are rather limited. If I check the file ./includes/restler/framework/Luracast/Restler/Data/Validator.php I find a hint that the request cannot valudate the class array<string,string>. That doesn’t get me any further. The payload must have a different structure. But how?

Has anybody an idea?
Help appreciated.

hi. Here’s how I use the API.

  1. create some object inside Dolibarr using the GUI
  2. get that very same object using the API
  3. copy the json, modify it a bit and feed it back to the API
  4. Failure? change the modification
  5. Success? go check out the object inside Dolibarr so I understand the field relations
1 Like

hi,
thanks for your reply.
I followed exactly what you described.
I removed the id attribute, followed by the others step by step.
The only response is

{
  "error": {
    "code": 400,
    "message": "Bad Request: Invalid value specified for `request_data` class not exists: array<string,string> array<string,string>"
  },
  "debug": {
    "source": "Validator.php:720 at validate stage",
    "stages": {
      "success": [
        "get",
        "route",
        "negotiate",
        "authenticate"
      ],
      "failure": [
        "validate",
        "message"
      ]
    }
  }
}

Hey, I just remembered that I was hit by something similar

The patch worked like a charm. POST /members give http 200. The member record is getting created now.

Saved my day.
Thanks.

1 Like