   params               = { url, body }
   defaultRequestParams = generateDefaultRequestParams params
   requestParams        = deepObjectExtend defaultRequestParams, opts
-  # after deep extending object, encodes body param to a query string
-  requestParams.body   = querystring.stringify requestParams.body
 
-  return requestParams
+  # return without creating a team invitation
+  if opts.createTeamInvitation is no
+    # after deep extending object, encodes body param to a query string
+    requestParams.body = querystring.stringify requestParams.body
+    return callback requestParams
+
+  slug  = opts.body ? body.slug
+  email = opts.email ? body.email
+
+  JTeamInvitation.create { groupName : slug, email }, (err, teamInvitation) ->
+    expect(err).to.not.exist
+    requestParams.body.teamAccessCode = teamInvitation.code
+    requestParams.body                = querystring.stringify requestParams.body
+    return callback requestParams
 
 
 module.exports = {

querystring = require 'querystring'

{ generateUrl
  deepObjectExtend
  generateRandomEmail
  generateRandomString

  companyName = "testcompany#{generateRandomString(10)}"

  defaultBodyObject =
    slug           : companyName
    email          : generateRandomEmail()
    agree          : 'on'
    allow          : 'true'
    domains        : 'koding.com, gmail.com'
    invitees       : invitees
    redirect       : ''
    username       : username
    password       : 'testpass'
    newsletter     : 'true'
    companyName    : companyName
    alreadyMember  : 'false'
    teamAccessCode : ''
    passwordConfirm: 'testpass'

  deepObjectExtend defaultBodyObject, opts

