Chilkat Online Tools

Swift / Postman API / Create User

Back to Collection Items

func chilkatTest() {
    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let http = CkoHttp()
    var success: Bool

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

    // The following JSON is sent in the request body.

    // {
    //   "schemas": [
    //     "urn:ietf:params:scim:schemas:core:2.0:User"
    //   ],
    //   "userName": "{{userEmail}}",
    //   "name": {
    //     "givenName": "Test",
    //     "familyName": "User"
    //   },
    //   "externalId": "23123123",
    //   "locale": "en-US",
    //   "groups": [
    //   ],
    //   "active": true
    // }

    let json = CkoJsonObject()
    json.UpdateString("schemas[0]", value: "urn:ietf:params:scim:schemas:core:2.0:User")
    json.UpdateString("userName", value: "{{userEmail}}")
    json.UpdateString("name.givenName", value: "Test")
    json.UpdateString("name.familyName", value: "User")
    json.UpdateString("externalId", value: "23123123")
    json.UpdateString("locale", value: "en-US")
    json.UpdateNewArray("groups")
    json.UpdateBool("active", value: true)

    http.SetRequestHeader("Authorization", value: "{{apiKey}}")
    http.SetRequestHeader("X-API-Key", value: "{{postman_api_key}}")

    var resp: CkoHttpResponse? = http.PostJson3("https://api.getpostman.com/scim/v2/Users", contentType: "application/json", json: json)
    if http.LastMethodSuccess == false {
        print("\(http.LastErrorText)")
        return
    }

    print("\(resp!.StatusCode.intValue)")
    print("\(resp!.BodyStr)")
    resp = nil

}

Curl Command

curl -X POST
	-H "X-API-Key: {{postman_api_key}}"
	-H "Authorization: {{apiKey}}"
	-d '{
    "schemas": ["urn:ietf:params:scim:schemas:core:2.0:User"],
    "userName": "{{userEmail}}",
    "name": {
        "givenName": "Test",
        "familyName": "User"
    },
    "externalId": "23123123",
    "locale": "en-US",
    "groups": [],
    "active": true
}'
https://api.getpostman.com/scim/v2/Users

Postman Collection Item JSON

{
  "name": "Create User",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Authorization",
        "value": "{{apiKey}}",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {\n        \"givenName\": \"Test\",\n        \"familyName\": \"User\"\n    },\n    \"externalId\": \"23123123\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.getpostman.com/scim/v2/Users",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "scim",
        "v2",
        "Users"
      ]
    },
    "description": "Creates a new user account in Postman, adds the user to your organization's Postman team, and activates the user to authenticate into your Postman team, provided an account with the same email ID does not already exist in Postman. The newly added user will have the `developer` role in Postman by default. You can later [update user roles in Postman](/docs/administration/managing-your-team/managing-your-team/#managing-roles).\n\nIf an account with the same email ID does exist, an [email invite](https://learning.postman.com/docs/administration/managing-your-team/managing-your-team/#invites) to join your Postman team is sent to the user. Once the user accepts the invite, they will be added to your team."
  },
  "response": [
    {
      "name": "201 - User Creation Successful",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {\n        \"givenName\": \"Test\",\n        \"familyName\": \"User\"\n    },\n    \"externalId\": \"23123123\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "status": "Created",
      "code": 201,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:schemas:core:2.0:User\"\n    ],\n    \"id\": \"405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99\",\n    \"userName\": \"testUser@postman.local\",\n    \"name\": {\n        \"givenName\": \"Test\",\n        \"familyName\": \"User\"\n    },\n    \"externalId\": \"23123123\",\n    \"active\": true,\n    \"meta\": {\n        \"resourceType\": \"User\",\n        \"created\": \"2021-02-22T04:24:13.000Z\",\n        \"lastModified\": \"2021-02-22T04:24:13.000Z\"\n    }\n}"
    },
    {
      "name": "400 - Invalid request body",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {},\n    \"emails\": [{\n        \"primary\": true,\n        \"value\": \"{{userEmail}}\",\n        \"type\": \"work\"\n    }],\n    \"displayName\": \"Test User\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"scimType\": \"invalidSyntax\",\n    \"detail\": \"The request body seems to be incomplete or have unsupported characters.\",\n    \"status\": \"400\"\n}"
    },
    {
      "name": "400 - Not Enterprise",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {},\n    \"emails\": [{\n        \"primary\": true,\n        \"value\": \"{{userEmail}}\",\n        \"type\": \"work\"\n    }],\n    \"displayName\": \"Test User\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"detail\": \"Only Postman teams on the Enterprise plan can use SCIM provisioning. Upgrade your plan.\",\n    \"status\": \"400\"\n}"
    },
    {
      "name": "400 - No slots",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {},\n    \"emails\": [{\n        \"primary\": true,\n        \"value\": \"{{userEmail}}\",\n        \"type\": \"work\"\n    }],\n    \"displayName\": \"Test User\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"detail\": \"No slots available on your Postman team. Purchase or free up slots to invite more members. For help, contact Team Admins or members with a Billing role.\",\n    \"status\": \"400\"\n}"
    },
    {
      "name": "400 - Invalid team",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {},\n    \"emails\": [{\n        \"primary\": true,\n        \"value\": \"{{userEmail}}\",\n        \"type\": \"work\"\n    }],\n    \"displayName\": \"Test User\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"detail\": \"This Postman team doesn’t exist anymore.\",\n    \"status\": \"400\"\n}"
    },
    {
      "name": "401 - Invalid API key",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {\n        \"givenName\": \"Test\",\n        \"familyName\": \"User\"\n    },\n    \"emails\": [{\n        \"primary\": true,\n        \"value\": \"{{userEmail}}\",\n        \"type\": \"work\"\n    }],\n    \"displayName\": \"Test User\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "status": "Unauthorized",
      "code": 401,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"detail\": \"Unable to access the team. Check if you have entered a valid API key.\",\n    \"status\": \"401\"\n}"
    },
    {
      "name": "403 - Admin team mismatch",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {},\n    \"emails\": [{\n        \"primary\": true,\n        \"value\": \"{{userEmail}}\",\n        \"type\": \"work\"\n    }],\n    \"displayName\": \"Test User\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"detail\": \"Your API key was generated by a Team Admin who is no longer on your team. Use an API key generated by a Team Admin.\",\n    \"status\": \"403\"\n}"
    },
    {
      "name": "409 - User already exists",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {\n        \"givenName\": \"Test\",\n        \"familyName\": \"User\"\n    },\n    \"emails\": [{\n        \"primary\": true,\n        \"value\": \"{{userEmail}}\",\n        \"type\": \"work\"\n    }],\n    \"displayName\": \"Test User\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "status": "Conflict",
      "code": 409,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"scimType\": \"uniqueness\",\n    \"detail\": \"This person is already a member of the team.\",\n    \"status\": \"409\"\n}"
    },
    {
      "name": "429 - Rate limit exceeded",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {\n        \"givenName\": \"Test\",\n        \"familyName\": \"User\"\n    },\n    \"externalId\": \"23123123\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"detail\": \"That’s 180 attempts in less than a minute. Wait for a minute and then try again.\",\n    \"status\": 429\n}"
    },
    {
      "name": "500 - Something went wrong",
      "originalRequest": {
        "method": "POST",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"schemas\": [\"urn:ietf:params:scim:schemas:core:2.0:User\"],\n    \"userName\": \"{{userEmail}}\",\n    \"name\": {\n        \"givenName\": \"Test\",\n        \"familyName\": \"User\"\n    },\n    \"emails\": [{\n        \"primary\": true,\n        \"value\": \"{{userEmail}}\",\n        \"type\": \"work\"\n    }],\n    \"displayName\": \"Test User\",\n    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users"
          ]
        }
      },
      "status": "Internal Server Error",
      "code": 500,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"detail\": \"Unable to add members to the team. Try again — it should work next time around.\",\n    \"status\": \"500\"\n}"
    }
  ]
}