Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact

[Resolved] Error when creating a member with the API

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.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • June 27, 2025 at 9:25 am #30697
    Mani45
    Participant

    I’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:doe

    The url is https://mycanonicalurl/?swpm_api_action=create&key=5e4aa7acd2858b45xxxxxxxxxxxxxxxx&email=jane.doe@test.com&
    first_name=jane&last_name=doe

    When 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 #30702
    Mani45
    Participant

    I 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 #30705
    The Assurer
    Moderator

    I 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.

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy