Chilkat Online Tools

C / Postman API / Update User Information

Back to Collection Items

#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>

void ChilkatSample(void)
    {
    HCkHttp http;
    BOOL success;
    HCkJsonObject json;
    HCkStringBuilder sbRequestBody;
    HCkHttpResponse resp;

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

    http = CkHttp_Create();

    // 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
    // }

    json = CkJsonObject_Create();
    CkJsonObject_UpdateString(json,"schemas[0]","urn:ietf:params:scim:schemas:core:2.0:User");
    CkJsonObject_UpdateString(json,"userName","{{userEmail}}");
    CkJsonObject_UpdateString(json,"name.givenName","Test");
    CkJsonObject_UpdateString(json,"name.familyName","User");
    CkJsonObject_UpdateString(json,"externalId","23123123");
    CkJsonObject_UpdateString(json,"locale","en-US");
    CkJsonObject_UpdateNewArray(json,"groups");
    CkJsonObject_UpdateBool(json,"active",TRUE);

    CkHttp_SetRequestHeader(http,"Authorization","{{apiKey}}");
    CkHttp_SetRequestHeader(http,"X-API-Key","{{postman_api_key}}");

    sbRequestBody = CkStringBuilder_Create();
    CkJsonObject_EmitSb(json,sbRequestBody);

    resp = CkHttp_PTextSb(http,"PUT","https://api.getpostman.com/scim/v2/Users/{{id}}",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
    if (CkHttp_getLastMethodSuccess(http) == FALSE) {
        printf("%s\n",CkHttp_lastErrorText(http));
        CkHttp_Dispose(http);
        CkJsonObject_Dispose(json);
        CkStringBuilder_Dispose(sbRequestBody);
        return;
    }

    printf("%d\n",CkHttpResponse_getStatusCode(resp));
    printf("%s\n",CkHttpResponse_bodyStr(resp));
    CkHttpResponse_Dispose(resp);


    CkHttp_Dispose(http);
    CkJsonObject_Dispose(json);
    CkStringBuilder_Dispose(sbRequestBody);

    }

Curl Command

curl -X PUT
	-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/{{id}}

Postman Collection Item JSON

{
  "name": "Update User Information",
  "request": {
    "method": "PUT",
    "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/{{id}}",
      "protocol": "https",
      "host": [
        "api",
        "getpostman",
        "com"
      ],
      "path": [
        "scim",
        "v2",
        "Users",
        "{{id}}"
      ]
    },
    "description": "Updates a user’s first and last name in Postman. \n\n> Only updates made to the user’s given and family name via the SCIM API will be pushed to Postman. No other user attributes can be updated in Postman using the SCIM API."
  },
  "response": [
    {
      "name": "200",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apikey}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_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\": \"test.user@okta.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 - Can't update username",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "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\": \"Couldn’t update this team member’s username. Try again — it should work next time around.\",\n    \"status\": \"400\"\n}"
    },
    {
      "name": "400 - Invalid team",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "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": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "invalidApiKey",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "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": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "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": "400 - Invalid payload",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "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    \"locale\": \"en-US\",\n    \"groups\": [],\n    \"active\": true\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "{{url}}/Users/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "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": "403 - Admin action not allowed",
      "originalRequest": {
        "method": "PUT",
        "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "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\": \"The admin is not allowed to perform this action.\",\n    \"status\": \"403\"\n}"
    },
    {
      "name": "403 - User not in Team",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "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\": \"This person isn’t a member of the team.\",\n    \"status\": \"403\"\n}"
    },
    {
      "name": "404 - User Not Found",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": null,
      "cookie": [
      ],
      "body": "{\n    \"schemas\": [\n        \"urn:ietf:params:scim:api:messages:2.0:Error\"\n    ],\n    \"detail\": \"This person isn’t a member of the team.\",\n    \"status\": \"404\"\n}"
    },
    {
      "name": "429 - Rate limit exceeded",
      "originalRequest": {
        "method": "PUT",
        "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "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": "PUT",
        "header": [
          {
            "key": "Authorization",
            "value": "{{apiKey}}",
            "type": "text"
          },
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "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/405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99",
          "host": [
            "{{url}}"
          ],
          "path": [
            "Users",
            "405775fe15ed41872a8eea4c8aa2b38cda9749812cc55c99"
          ]
        }
      },
      "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\": \"Couldn’t update this team member’s information. Try again — it should work next time around.\",\n    \"status\": \"500\"\n}"
    }
  ]
}