Using API to update form entry on Formidable registration form

By: Tabbitha Garcia | Asked: 08/16/2023
ForumsCategory: Code HelpUsing API to update form entry on Formidable registration form
Tabbitha Garcia asked 8 months ago

Trying out Formidable’s API key to update all user profiles via my registration form in Formidable.

What am I trying to do?
Update all my users so that they can have industry_format meta present in the db

What does my code do?
In summary, this code ensures that whenever a user's profile is updated, the "industry_format" user meta is updated to reflect the formatted and sanitized version of the user's selected industries. This helps maintain consistency and accurate data in the user meta fields. Industry is where the user selects any industry that best describes them. *See photo* Here's what I've done:

  • Grabbed the API key in formidable settings
  • Making sure I have the correct form id: 34
  • Making sure POST req is correct with appropriate URL, headers, and body. And yes, I have tried not adding ‘bearer’ to the value and just rendering the key alone. Still does not work.

As you can see there is an error "code": "rest_no_route", "message": "No route was found matching the URL and request method.", "data": { "status": 404 Went through these troubleshooting steps: The "No route was found matching the URL and request method" error with a status of 404 indicates that the API endpoint you're trying to access is not recognized by the server. This can happen for several reasons:

  1. Incorrect URL: Double-check the URL you're using. Make sure it's correctly formatted and matches the expected structure of the Formidable Forms API. The URL should be in the format: https://stg-central.vib.community/wp-json/frm/v2/forms/{form_id}/entries.
  2. Incorrect Form ID: Verify that the {form_id} placeholder is replaced with the actual ID of the form you want to work with. Ensure that the form ID is correct and corresponds to a form in your Formidable Forms setup.
  3. API Key: Ensure that you're using the correct API key and that it's included in the "Authorization" header with the "Bearer" prefix.
  4. Endpoint Availability: Check if the Formidable Forms API is enabled and accessible on your site. Some sites may restrict API access, or there might be an issue with the API setup.
  5. Version Compatibility: Make sure that the API endpoint structure and version (/frm/v2/) matches the version of Formidable Forms you're using.
  6. Authentication: Confirm that your API key has the necessary permissions to create entries for the specified form.

To troubleshoot this further:

  • Verify the form ID, URL, and headers are correctly set in Postman.
  • Double-check your Formidable Forms settings for API access and key generation.
  • Review any documentation or guidelines provided by Formidable Forms for using their API.

    I went through these troubleshooting methods. Can anyone please look over to see if I set this up properly? What am I missing here?

Attachments
Question Tags:
1 Answers
Victor Font answered 8 months ago
You're not going about this the right way and I also have no idea why you're trying to use the REST API. First, the WordPress profile_update() action, only fires after a user's record is updated. It does not update a user record without another update taking place first. See these: https://developer.wordpress.org/reference/hooks/profile_update/ and https://github.com/WordPress/wordpress-develop/blob/6.3/src/wp-includes/user.php#L2464-L2464
Victor Font replied 8 months ago

Next, your update code is wrong. WordPress does not store empty meta values and you test for empty value then use update_user_meta. If the field doesn't exist, you need to add it. There's nothing to update.

If you're trying to do a bulk update, write a PHP function that loops through all users to update them accordingly. The easiest approach is to fire the function in functions.php so it all updates before the site is loaded. Thereafter, you can use frm_after_create_entry and frm_after_update_entry to update records going forward.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right