Chilkat Online Tools

Foxpro / MongoDB Atlas / Add Teams to a Project

Back to Collection Items

LOCAL loHttp
LOCAL lnSuccess
LOCAL loJarr
LOCAL loJsonObj_1
LOCAL loSbRequestBody
LOCAL loResp

* This example assumes the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http')
loHttp = CreateObject('Chilkat.Http')

loHttp.DigestAuth = 1
loHttp.Login = "username"
loHttp.Password = "password"

* Use this online tool to generate code from sample JSON: Generate Code to Create JSON

* The following JSON is sent in the request body.

* [
*   {
*     "teamId": "601cca55e6a61770dd7c3611",
*     "roleNames": [
*       "GROUP_OWNER"
*     ]
*   }
* ]

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonArray')
loJarr = CreateObject('Chilkat.JsonArray')

loJarr.AddObjectAt(-1)
loJsonObj_1 = loJarr.ObjectAt(loJarr.Size - 1)
loJsonObj_1.UpdateString("teamId","601cca55e6a61770dd7c3611")
loJsonObj_1.UpdateString("roleNames[0]","GROUP_OWNER")
RELEASE loJsonObj_1

* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbRequestBody = CreateObject('Chilkat.StringBuilder')
loJarr.EmitSb(loSbRequestBody)

loResp = loHttp.PTextSb("POST","https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/teams",loSbRequestBody,"utf-8","application/json",0,0)
IF (loHttp.LastMethodSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJarr
    RELEASE loSbRequestBody
    CANCEL
ENDIF

? STR(loResp.StatusCode)
? loResp.BodyStr
RELEASE loResp

RELEASE loHttp
RELEASE loJarr
RELEASE loSbRequestBody

Curl Command

curl -X POST
	--digest -u 'username:password'
	-d '[
    {
        "teamId": "601cca55e6a61770dd7c3611",
        "roleNames": [
            "GROUP_OWNER"
        ]
    }
]'
https://domain.com/api/atlas/{{version}}/groups/{{ProjectID}}/teams

Postman Collection Item JSON

{
  "name": "Add Teams to a Project",
  "request": {
    "method": "POST",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "[\n    {\n        \"teamId\": \"601cca55e6a61770dd7c3611\",\n        \"roleNames\": [\n            \"GROUP_OWNER\"\n        ]\n    }\n]",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "{{base_url}}/api/atlas/{{version}}/groups/{{ProjectID}}/teams",
      "host": [
        "{{base_url}}"
      ],
      "path": [
        "api",
        "atlas",
        "{{version}}",
        "groups",
        "{{ProjectID}}",
        "teams"
      ]
    },
    "description": "https://docs.atlas.mongodb.com/reference/api/project-add-team/"
  },
  "response": [
  ]
}