Error 307 with POST request

64 views
Skip to first unread message

Mamy TOMBOZAFY

unread,
Jun 28, 2025, 5:38:07 AM6/28/25
to Google Apps Script Community
Hello guys!

I'm trying to write a code to create a member in a wordpress website using the simple membership plugin.

I've configured everything within the plugin and I have an API key.

I've tested the API with Postman and it works with a 200 status. The member was added successfully.

params-postman.png
body-postman.png

But when I try with this apps script code, I get an error 307. 

function createMember() {

var body = {
first_name: 'John',
last_name: 'Doe',
};

var options = {
method: 'POST',
contentType: 'multipart/form-data',
payload: body,
muteHttpExceptions: true
};

var response = UrlFetchApp.fetch(url, options);
var responseCode = response.getResponseCode();
Logger.log('response code : ' + responseCode);

}

Could someone help me figuring out the problem? Thanks!

Zack Reynolds

unread,
Jun 28, 2025, 9:02:31 AM6/28/25
to google-apps-sc...@googlegroups.com

Probably need to stringify the payload, in the options object, you can just do:
payload: JSON.stringify(body),


--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-script-community/cd172f9c-3764-415c-a086-2f6a48b9b2afn%40googlegroups.com.
Message has been deleted
Message has been deleted

DimuDesigns

unread,
Jun 29, 2025, 9:04:26 AM6/29/25
to Google Apps Script Community
HTTP 307 (aka Temporary Redirect) is relatively new - it was fully implemented in Chrome back in 2022(according to Google Gemini). UrlFetchApp automatically follows 302 redirects but it may not have support for 307 as yet.

Is there an option on the Wordpress side of things that would force 302 redirects instead of 307? If not, maybe you can try redirecting the request yourself. The redirect URL should be in the Location header of the HTTP response for temporary redirects.  

DimuDesigns

unread,
Jun 29, 2025, 9:04:26 AM6/29/25
to Google Apps Script Community
HTTP 307 (Temporary Redirect) is relatively new. If was implemented in Chrome in 2022 which is fairly recent by some standards. App Script's UrlFetchApp supports 302 redirects, but 307 may not be available yet.

Is there a configuration option in Wordpress that would use 302 instead or disable redirects altogether? If not you can try to handle the redirect yourself. The redirect URL should be in the Location header of the HTTP response .

On Saturday, June 28, 2025 at 9:02:31 AM UTC-4 Zack Reynolds wrote:
Reply all
Reply to author
Forward
0 new messages