Simple Membership Plugin › Forums › Simple Membership Plugin › Error when creating a member with the API
- This topic has 2 replies, 2 voices, and was last updated 1 year, 1 month ago by
The Assurer.
-
AuthorPosts
-
June 27, 2025 at 9:25 am #30697
Mani45
ParticipantI’m trying to create a new member with the API. I followed the documentation for the HTTP Post method and set the the following parameters:
key:5e4aa7acd2858b45xxxxxxxxxxxxxxxx
swpm_api_action:create
email:john.doe@email.com
first_name:john
last_name:doeThe url is https://mycanonicalurl/?swpm_api_action=create&key=5e4aa7acd2858b45xxxxxxxxxxxxxxxx&email=jane.doe@test.com&
first_name=jane&last_name=doeWhen I try it, I got the error message {“result”:”failure”,”message”:”Missing one of the mandatory fields: first_name, last_name, email. Ensure that you are using HTTP POST method to send the data.”}
I tried the GET method and it worked perfectly. But what’s wrong with the POST method?
June 27, 2025 at 7:51 pm #30702Mani45
ParticipantI managed to make it work with Postman by putting swpm_api_action and key in “Params” and first_name, last_name and email in “Body” and by choosing form-data. It gives a 200 OK status and the member is created in WP.
But now I’m trying to do the same thing with a code written with apps script:
function make_POST() {
var url = ‘https://mycanonicalurl/?swpm_api_action=create&key=5e4aa7acd2858b45xxxxxxxxxxxxxxxxx’;var body = {
first_name: ‘Bruce’,
last_name: ‘Wayne’,
email: ‘bwayne@example.com’
};var options = {
method: ‘POST’,
payload: JSON.stringify(body),
muteHttpExceptions: true
};//try {
var response = UrlFetchApp.fetch(url, options);
var responseCode = response.getResponseCode();
Logger.log(‘response code: ‘ + responseCode);
/*}
I got an error code 307 and it doesn’t create the member.
Someone can help to figure out the problem please?
June 28, 2025 at 1:28 am #30705The Assurer
ModeratorI pasted your code into Gemini and it came back with a number of errors. At the end of its critique of your code, it concluded with…
In summary, the main “errors” are the incomplete syntax (unclosed comment, unclosed block) and the problematic ’ in the URL. The smart quotes are a stylistic issue but can sometimes cause problems. The lack of try…catch is a best practice omission, not a syntax error, but crucial for robust code.
-
AuthorPosts
- You must be logged in to reply to this topic.