TheJumpCloud / jcapi-python

21 stars 21 forks source link

bulk_users_create API does not work #37

Open zaro0508 opened 4 years ago

zaro0508 commented 4 years ago

I'm trying to create users with the bulk_users_create API in the jcapi2 library. My test script runs without error however the user(s) is not created on our jumpcloud service.

Script:

from __future__ import print_function
import jcapiv2
from jcapiv2.rest import ApiException
from pprint import pprint

# Configure API key authorization: x-api-key
configuration = jcapiv2.Configuration()
configuration.api_key['x-api-key'] = 'XXXXXXXXXXXXXXXXXX'
# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
# configuration.api_key_prefix['x-api-key'] = 'Bearer'

# create an instance of the API class
api_instance = jcapiv2.BulkJobRequestsApi(jcapiv2.ApiClient(configuration))
content_type = 'application/json' # str |  (default to application/json)
accept = 'application/json' # str |  (default to application/json)
x_org_id = '' # str |  (optional) (default to )
body = [
  {
    "email": "sally.hunt@sagebase.org",
    "username": "shunt",
    "firstname": "Sally",
    "lastname": "Hunt"
  }
]

try:
    # Bulk Users Create
    api_response = api_instance.bulk_users_create(content_type, accept, body=body, x_org_id=x_org_id)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling BulkJobRequestsApi->bulk_users_create: %s\n" % e)

Execution:

python ./test.py
{'job_id': '5da4cf6113973a47cc6862fa'}
kmoorehead-jc commented 4 years ago

Hi zaro0508!

It looks like you did get a job id as a response from that call. If the users were not created, then the results of that job will likely contain some additional information to help us track down any possible issues here. Would you be able to query that job id with the following curl example and send the results along? Many thanks!

curl -X GET \\ https://console.jumpcloud.com/api/v2/bulk/users/{XXXX job-id XXXX}/results \\ -H 'Accept: application/json' \\ -H 'Content-Type: application/json' \\ -H 'x-api-key: {XXXX api-key XXXX}'

zaro0508 commented 4 years ago

The return error there is no connection available seems bogus because if I replace api_instance.bulk_users_create with api_instance.groups_user_list in my script it executes without error.

➜  python ./test.py
{'job_id': '5da5f9f85a97504b1a07379c'}

➜  accounts curl -X GET https://console.jumpcloud.com/api/v2/bulk/users/5da5f9f85a97504b1a07379c/results -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'x-api-key: XXXXXXXXXXXXXX'
[{"id":"5da5f9f85a97504b1a07379d","status":"errored","statusMsg":"there is no connection available","meta":{"systemUser":{"email":"sally.hunt@sagebase.org","username":"shunt","firstname":"Sally","lastname":"Hunt","attributes":[]}},"createdAt":"2019-10-15T16:55:20.081Z","updatedAt":"2019-10-15T16:55:20.126Z","persistedFields":null}]%
zaro0508 commented 4 years ago

I have verified that bulk_users_create api seems to be working as expected now. I have no idea who or what fixed this issue though.

kmoorehead-jc commented 4 years ago

Afternoon zaro0508,

Apologies on the bit delay in the response on this issue, but I do have some good news for you! It appears that you example that you provided is exactly correct.

The reason that you were not seeing the users created and getting the There is no connection available. error was due to a bug on the /api/v2/bulk/users endpoint that impacted all iterations of it (the SDKs, the API, the Pwsh Module and some GUI pieces as well). As you noted, this bug has now been fixed and the fix pushed to production so you're example should be working as intended now.

Thanks and have a good weekend!