Back to Collection Items
LOCAL loHttp
LOCAL lnSuccess
LOCAL loJson
LOCAL loResp
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcId
LOCAL lcExternalId
LOCAL lcSignedUpAt
LOCAL lcGivenName
LOCAL lcSurname
LOCAL lcV_Email
LOCAL lcAvatarUrl
LOCAL lcLang
* 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.BasicAuth = 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.
* {
* "externalId": "your-own-id",
* "signedUpAt": "2020-05-21T15:53:30.197Z",
* "profile": {
* "givenName": "Jane",
* "surname": "Doe",
* "email": "jane.doe@gmail.com",
* "avatarUrl": "https://s3.amazonaws.com/avatar.jpg"
* },
* "metadata": {
* "lang": "en-ca"
* }
* }
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJson = CreateObject('Chilkat.JsonObject')
loJson.UpdateString("externalId","your-own-id")
loJson.UpdateString("signedUpAt","2020-05-21T15:53:30.197Z")
loJson.UpdateString("profile.givenName","Jane")
loJson.UpdateString("profile.surname","Doe")
loJson.UpdateString("profile.email","jane.doe@gmail.com")
loJson.UpdateString("profile.avatarUrl","https://s3.amazonaws.com/avatar.jpg")
loJson.UpdateString("metadata.lang","en-ca")
loHttp.SetRequestHeader("Content-Type","application/json")
loResp = loHttp.PostJson3("https://domain.com/","application/json",loJson)
IF (loHttp.LastMethodSuccess = 0) THEN
? loHttp.LastErrorText
RELEASE loHttp
RELEASE loJson
CANCEL
ENDIF
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder')
loSbResponseBody = CreateObject('Chilkat.StringBuilder')
loResp.GetBodySb(loSbResponseBody)
* For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject')
loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
? "Response Header:"
? loResp.Header
? "Failed."
RELEASE loResp
RELEASE loHttp
RELEASE loJson
RELEASE loSbResponseBody
RELEASE loJResp
CANCEL
ENDIF
RELEASE loResp
* Sample JSON response:
* (Sample code for parsing the JSON response is shown below)
* {
* "user": {
* "id": "7494535bff5cef41a15be74d",
* "externalId": "your-own-id",
* "signedUpAt": "2020-05-21T15:53:30.197Z",
* "profile": {
* "givenName": "Jane",
* "surname": "Doe",
* "email": "jane.doe@gmail.com",
* "avatarUrl": "https://s3.amazonaws.com/avatar.jpg"
* },
* "metadata": {
* "lang": "en-ca"
* }
* }
* }
* Sample code for parsing the JSON response...
* Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
lcId = loJResp.StringOf("user.id")
lcExternalId = loJResp.StringOf("user.externalId")
lcSignedUpAt = loJResp.StringOf("user.signedUpAt")
lcGivenName = loJResp.StringOf("user.profile.givenName")
lcSurname = loJResp.StringOf("user.profile.surname")
lcV_Email = loJResp.StringOf("user.profile.email")
lcAvatarUrl = loJResp.StringOf("user.profile.avatarUrl")
lcLang = loJResp.StringOf("user.metadata.lang")
RELEASE loHttp
RELEASE loJson
RELEASE loSbResponseBody
RELEASE loJResp
Curl Command
curl -X POST
-u 'username:password'
-H "Content-Type: application/json"
-d '{
"externalId": "your-own-id",
"signedUpAt": "2020-05-21T15:53:30.197Z",
"profile": {
"givenName": "Jane",
"surname": "Doe",
"email": "jane.doe@gmail.com",
"avatarUrl": "https://s3.amazonaws.com/avatar.jpg"
},
"metadata": {
"lang": "en-ca"
}
}'
https://domain.com/
Postman Collection Item JSON
{
"name": "Create User",
"_postman_id": "44749d06-472c-4409-82b1-abc8a22ad666",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"externalId\": \"your-own-id\",\n \"signedUpAt\": \"2020-05-21T15:53:30.197Z\",\n \"profile\": {\n \"givenName\": \"Jane\",\n \"surname\": \"Doe\",\n \"email\": \"jane.doe@gmail.com\",\n \"avatarUrl\": \"https://s3.amazonaws.com/avatar.jpg\"\n },\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"url": "{{url}}/v2/apps/{{appId}}/users",
"description": "Creates a new user."
},
"response": [
{
"id": "2f2a4e6e-0d1a-4483-b30d-160379704ff5",
"name": "User already exists",
"originalRequest": {
"method": "POST",
"header": [
{
"description": {
"content": "Added as a part of security scheme: bearer",
"type": "text/plain"
},
"key": "Authorization",
"value": "Bearer <token>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"externalId\": \"your-own-id\",\n \"signedUpAt\": \"2020-05-21T15:53:30.197Z\",\n \"profile\": {\n \"givenName\": \"Jane\",\n \"surname\": \"Doe\",\n \"email\": \"jane.doe@gmail.com\",\n \"avatarUrl\": \"https://s3.amazonaws.com/avatar.jpg\"\n },\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/v2/apps/:appId/users",
"host": [
"{{baseUrl}}"
],
"path": [
"v2",
"apps",
":appId",
"users"
],
"variable": [
{
"key": "appId"
}
]
}
},
"status": "Conflict",
"code": 409,
"_postman_previewlanguage": "text",
"header": [
{
"key": "Content-Type",
"value": "text/plain"
}
],
"cookie": [
],
"body": ""
},
{
"id": "6a8ada4a-ff1f-4176-9d03-904fbc145bb6",
"name": "Created",
"originalRequest": {
"method": "POST",
"header": [
{
"description": {
"content": "Added as a part of security scheme: bearer",
"type": "text/plain"
},
"key": "Authorization",
"value": "Bearer <token>"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"externalId\": \"your-own-id\",\n \"signedUpAt\": \"2020-05-21T15:53:30.197Z\",\n \"profile\": {\n \"givenName\": \"Jane\",\n \"surname\": \"Doe\",\n \"email\": \"jane.doe@gmail.com\",\n \"avatarUrl\": \"https://s3.amazonaws.com/avatar.jpg\"\n },\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n}"
},
"url": {
"raw": "{{baseUrl}}/v2/apps/:appId/users",
"host": [
"{{baseUrl}}"
],
"path": [
"v2",
"apps",
":appId",
"users"
],
"variable": [
{
"key": "appId"
}
]
}
},
"status": "Created",
"code": 201,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"user\": {\n \"id\": \"7494535bff5cef41a15be74d\",\n \"externalId\": \"your-own-id\",\n \"signedUpAt\": \"2020-05-21T15:53:30.197Z\",\n \"profile\": {\n \"givenName\": \"Jane\",\n \"surname\": \"Doe\",\n \"email\": \"jane.doe@gmail.com\",\n \"avatarUrl\": \"https://s3.amazonaws.com/avatar.jpg\"\n },\n \"metadata\": {\n \"lang\": \"en-ca\"\n }\n }\n}"
}
]
}