You don't need line 14 or 15 in your example. The rest should work. What does the BE_CurlTrace function give you after the failure?
What version of the plugin do you have?
Thanks for responding. I'm using version 3.3.3 of the plug-in. The change log doesn't indicate any changes to this portion of the plug-in, but I'll try upgrading to 3.3.4 to see if it makes a difference.
I took out lines 14 and 15 (I didn't see that they were necessary, but put them in to try and make things more explicit) and this is the relevant portion of the BE_Curl_Trace:
The API response is still: "Incorrect Content-Type. Only application/x-www-form-urlencoded is allowed."
When I look at the HTTP request in Postman (that works successfully) it gives this HTTP request:
POST /v2/auth/token HTTP/1.1
Authorization: Basic XXXXXX
I also discovered that I could get it to work successfully by directly calling curl (using BE_ExecuteSystemCommand):
BE_ExecuteSystemCommand ( "curl --request POST --url " & $URL & " --header 'Authorization: Basic " & $AuthString & "' --header 'Content-type: application/x-www-form-urlencoded' --data grant_type=client_credentials" )
I looked at the BaseElements plug-in code and I do see that CURLOPT_POSTFIELDS is actually being used in set_parameters( ).
If you have any other suggestions, please let me know.
I upgraded to 3.3.4, however I still get the same API response.
I was finally able to resolve this and get it to work with BE_HTTP_POST. It turns out that the Base64Encode function that was used to generate the authorization string was adding a linefeed character to the end of the string and it looks like this was causing problems. (I was aware that Base64Encode added linefeeds, but hadn't considered that the linefeeds would cause problems with the HTTP headers and it turns out that the authorization string was exactly 76 characters long, so the linefeed was the last character and wasn't easily visible. I had stripped out carriage returns from the authorization string, but not linefeeds :-( ) When I was testing with Postman and curl I was copying in the authorization string without the linefeed and so it worked correctly. I was able to get it to work with BE_HTTP_POST by removing the linefeed character from the authorization string.
My apologies for suggesting a deficiency with the BaseElements plugin. I'm glad I had an opportunity to look at the code. Impressive work!
Glad to hear it's sorted.