Date
1 - 10 of 10
Example signup form?
ajomccauley@...
Hi! Can I use the API to create a custom member signup form? I've looked in the docs, but I'm not sure if I'm not understanding how, or if I'm "not understanding" because it isn't possible to do.
Does anyone have an example of a custom signup form using the API (like that I could put on our organization website) they'd be willing to share or explain or both? Thanks so much! |
|
sierragamers@...
There are a couple of subtle nuances to this....
Registering a user is easy (two api calls, login and registeruser). However, that only adds the user and doesn't subscribe them to your group. They can't be subscribed (added to your group) until they confirm their email address. Thus, adding them as a user is somewhat useless. There is a "directadd" api call that is great, but requires a paid premium subscription. I experimented with it yesterday and found it worked great. It adds the user to the group immediately (although they still have to create an account the first time they sign in) In your case, what may make the most sense is to simply have them use an online form to sign up, from which you trigger a invitation to be sent (the invite endpoint). The invitation will give the user everything they need to create a password and join the group. -Ken W |
|
sierragamers@...
One tip for anyone experimenting with the API...
Download the free Windows utility called "Postman". I tested every api call in Postman prior to writing code. It saved me a ton of time. PS I have no affiliation with whoever makes the utility other than having enjoyed using it. |
|
ajomccauley@...
Thank you! I actually have a premium subscription, so I can use direct add, yay!
So, I'm a web developer, I know PHP, MySQL, some Python, and some JavaScript, BUT, I haven't used REST, and I'm just, lost about where to start. In particular, I don't understand how I would authenticate with the API, so that it lets me perform actions. Any chance you have an example you wouldn't mind sharing, to help me get off the ground...? Thanks so much! -Alison |
|
sierragamers@...
Greetings Alison,
My application is probably very different. I'm using Dot Net from the server side. That said, I'm putting some code at the end of this message. The thing I struggled with was that I couldn't get dot net to post to Groups.IO's servers. I had a couple of challenges that were easily overcome, but only after I discovered what they were. Specifically, the authentication is two-fold; the CSRF .. AND, the cookie that is obtained when you log in. Being server side, I had to create an empty cookie container, collect a cookie on the login and then give it back later for the DirectAdd call. My second challenge took a day to solve. Apparently Groups.IO's servers want TSL1 or 2, and dot net was trying to communicate with TLS 3. All I knew was the call was inexplicable timing out. Argh. Anyway .. there's no greater tip I can give you than to download Postman. https://www.getpostman.com/downloads/ I never would have figured it out otherwise. You really need to make the calls from Postman first to see the behavior. Anyway ... here's some excerpts from my code: This is the method that does the login .... (It's not likely to be much help) Function loginToGroupsIo(ByVal email As String, ByVal password As String) As GioInfo
Dim paramsInBody As Specialized.NameValueCollection = New Specialized.NameValueCollection
Dim paramsOnUrl As Specialized.NameValueCollection = New Specialized.NameValueCollection
paramsOnUrl.Add("email", email)
paramsOnUrl.Add("password", password)
Dim uri As String = "https://groups.io/api/v1/login"
Dim cookieContainer As Net.CookieContainer = New Net.CookieContainer
Dim rtn_generic As WpToolsV2.Rtn_generic = wp.GioPostHtmlv2(uri, paramsInBody, paramsOnUrl, "", cookieContainer)
If (rtn_generic.success) Then
Else
reportF.Append(rtn_generic.reason)
Return Nothing
End If
Dim js As JavaScriptSerializer = New JavaScriptSerializer
Dim loginObject As Object = js.DeserializeObject(rtn_generic.reason)
Dim userObject As Object = loginObject("user")
Dim gi As GioInfo = New GioInfo
gi.loggedInUserId = userObject("id")
gi.csrf = userObject("csrf_token")
gi.cookieContainer = cookieContainer
gi.userObject = userObject
gi.loginObject = loginObject
Return gi
End Function And the code for the DirectAdd: Sub addViaDirectAdd(ByRef gi As GioInfo,
ByRef listOfEmails As List(Of String))
Dim rtn_generic As WpToolsV2.Rtn_generic = Nothing
Dim js As JavaScriptSerializer = New JavaScriptSerializer
Dim paramsInBody As Specialized.NameValueCollection = New Specialized.NameValueCollection
Dim paramsOnUrl As Specialized.NameValueCollection = New Specialized.NameValueCollection
paramsInBody.Add("group_id", gi.groupid)
paramsInBody.Add("group_name", gi.group_name)
Dim newLine As String = vbCrLf
Dim f As FastString = New FastString
For Each email As String In listOfEmails
f.Append(email & newLine)
Next
paramsInBody.Add("emails", f.concat)
paramsInBody.Add("csrf", gi.csrf)
Dim uri As String = "https://groups.io/api/v1/directadd"
rtn_generic = wp.GioPostHtmlv2(uri, paramsInBody, paramsOnUrl, "", gi.cookieContainer)
If (rtn_generic.success) Then
Else
reportF.Append(rtn_generic.reason)
Return
End If
End Sub
Something worth noting ... Login is simple -- the parameters go on the URL. All of the other calls use the parameters inside the body of the email. Here is the source for my actual method that does the posting. It won't help you .. but .. someone down the line might find it useful... There is a lot of useless code within the method. I struggled to get it to work, so I was logging everything after every call so I could see what was happening. And, the code is a bit messy because "posting comes in various flavors" and I tried them all. At one point I was posting as a multi-part form, etc. Anyway .. I hope all this helps. Good luck! Public Function GioPostHtmlv2(
ByVal uri As String,
ByVal parametersInBody As Specialized.NameValueCollection,
ByVal parametersOnUrl As Specialized.NameValueCollection,
ByVal accessToken As String,
ByRef cookieContainer As CookieContainer) As Rtn_generic
Dim f As FastString = New FastString
f.Append("URI: " & uri & vbCrLf)
' make a parameter list
Dim parametersf As FastString = New FastString
Dim allKeys() As String = parametersOnUrl.AllKeys
Dim firstTime As Boolean = True
For Each key As String In allKeys
If (firstTime) Then
firstTime = False
parametersf.Append("?")
Else
parametersf.Append("&")
End If
parametersf.Append(key & "=")
parametersf.Append(HttpContext.Current.Server.UrlEncode(parametersOnUrl(key)))
Next
Dim postData As String = parametersf.concat
If (postData Is Nothing) Then
postData = ""
End If
uri &= postData
f.Append("URI with Parms: " & uri & vbCrLf)
System.Net.ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls12
Dim rtn As Rtn_generic = New Rtn_generic
Dim request As Net.HttpWebRequest = Net.WebRequest.Create(uri)
request.ContentType = "application/x-www-form-urlencoded"
f.Append(request.ContentType & vbCrLf)
request.Method = "POST"
request.KeepAlive = True
request.Credentials = Net.CredentialCache.DefaultCredentials
request.PreAuthenticate = True
request.Accept = "application/json"
If (accessToken = "") Then
Else
request.Headers.Add("Authorization", "Bearer " & accessToken)
End If
request.CookieContainer = cookieContainer
Using requestStream As IO.Stream = request.GetRequestStream()
parametersf.Reset()
allKeys = parametersInBody.AllKeys
firstTime = True
For Each key As String In allKeys
If (firstTime) Then
firstTime = False
parametersf.Append("")
Else
parametersf.Append("&")
End If
parametersf.Append(key & "=")
parametersf.Append(HttpContext.Current.Server.UrlEncode(parametersInBody(key)))
Next
postData = parametersf.concat
If (postData Is Nothing) Then
postData = ""
End If
f.Append("Parameters in the body:" & vbCrLf)
f.Append(postData & vbCrLf)
Dim parameterBytes As Byte() = Text.Encoding.UTF8.GetBytes(postData)
requestStream.Write(parameterBytes, 0, parameterBytes.Count)
End Using
Dim response As Net.WebResponse = Nothing
Try
response = request.GetResponse()
Using responseStream As IO.Stream = response.GetResponseStream()
Using responseReader As New IO.StreamReader(responseStream)
Dim responseText = responseReader.ReadToEnd()
Diagnostics.Debug.Write(responseText)
rtn.success = True
rtn.reason = responseText
End Using
End Using
Catch exception As Net.WebException
response = exception.Response
If (response IsNot Nothing) Then
Using reader As New IO.StreamReader(response.GetResponseStream())
Dim responseText = reader.ReadToEnd()
Diagnostics.Debug.Write(responseText)
rtn.success = False
rtn.reason = responseText
End Using
response.Close()
End If
Finally
request = Nothing
End Try
rtn.log = f.concat
Return rtn
End Function
|
|
Timothy Fong <timfong888@...>
When you authenticate against the login end point, your client will receive a cookie. Each subsequent request that uses that cookie let’s you perform the other actions. Postman has that option to mimic your actual client. On Sat, Nov 23, 2019 at 5:16 PM sierragamers via Groups.Io <sierragamers=kensblog.com@groups.io> wrote: Greetings Alison, --
|
|
ajomccauley@...
Hi Ken, thank you *so much* for sharing your code, and re-urging me to get Postman, which I just did :) If/when I figure more stuff out, I'll share back here!
(The reason for all this, for us, is that (a) the group owners want to collect more info than just email address, even though the other info won't go into the person's member record in groups.io (it's for verifying who people are); and, (b) they'd really like to have the Display Name populated from the start. I'm not sure if those are super common needs or if they're unusual, but, that's what I'm trying to figure out if I can put together for them.) Thanks again! -Alison |
|
ajomccauley@...
Oops I replied without refreshing the page first -- thank you, Tim!
Do y'all like, use your own email/password combos for this stuff (and then figure out securing the info depending on your server/software situation)? I'd love to know if that's the norm, b/c right now I feel like I've *got* to be missing something, but maybe I'm not... |
|
ajomccauley@...
(Still wondering about that last thing if anyone has any insight!) (But also -- )
Looks like we won't be using Direct Add after all, they want to approve subscription requests. I mean, the eeeeeasiest thing to do is use a webform on our website (it's Drupal so there's a webform module), send the webform submission to *both* the "+owner" and the "+subscribe" email addresses, ...and that's seriously it, we can collect whatever info we want in the webform (which they only want to have to check against their own records of who's a member of the community IRL), and the user will have a membership request pending approval. The automatic email from the webform submission is like, sort of from the submitting user's email address, and in my testing, it seems to work great -- but the Display Name isn't getting populated, and I can't figure out why. But that's probably out of scope for this thread -- I know I started the thread, but still :) I'll copy into a different thread. (But/And still would love advice on the username/password question I posed in my previous message! :) Thanks, Alison |
|
ajomccauley@...
Hi! Just a bump on this question, if anyone has some advice:
Do y'all use your own email/password combos for this stuff (and then figure out securing the info depending on your server/software situation)? I'd love to know if that's the norm, b/c right now I feel like I've *got* to be missing something, but maybe I'm not... |
|