I’m trying to use the enterprise API to enroll learners into a course and also create a record in EnterpriseCourseEnrollment.
I tried to use: http://local.overhang.io/enterprise/api/v1/enterprise-customer/<UUID>/course_enrollments following the example I see in the test.
However, when I send a request (using Thunderclient or curl) I get a 401 response. I tried the same token with other endpoints (e.g. /bulk_enroll/v1/bulk_enroll) and it works fine.
I also get a response when I make a request to /enterprise/api/v1/ but as soon as I tried to get /enterprise/api/v1/enterprise-customer/, I get a 401 response.
But then I get a AttributeError: 'NoneType' object has no attribute 'username'. (trace error.txt (3.8 KB)). I then tried to create an enterprise catalog from the LMS but I got the same error.
To clarify, the /bulk_enroll/v1/bulk_enroll endpoint lives in edx-platform, correct? That endpoint doesn’t factor in any enterprise-specific permissions which is why you’re able to get a valid response when calling it.
The /enterprise/api/v1/enterprise-customer/<UUID>/course_enrollmentsendpoint on the other hand, uses edx-rbac in order to limit access based on the enterprise-specific roles available to a user. As this endpoint uses the @permission_required decorator for the enterprise.can_enroll_learners rule (defined here), only users that have a role that matches that permissions rule will have access. In this case, it’s looking for the user to have the “enrollment_api_admin” feature role. Generally, our worker users (e.g., enterprise_worker, enterprise_catalog_worker) are granted this feature role such that we can make service-to-service calls to endpoints with permissions such as this one.
The permissions for the /enterprise/api/v1/enterprise-customer/ endpoint are based on whether or not your authenticated user is linked to at least one enterprise (via DjangoModelPermissions). Do you have have an EnterpriseCustomerUser record configured for your authenticated user to indicate they are linked to an enterprise? Staff/superuser users should get a valid response from this endpoint without an explicit EnterpriseCustomerUser, however.
Unfortunately, as you mentioned, the enterprise-catalog service is technically now a pre-requisite to use enterprise catalogs. When you create/update a catalog in edx-enterprise, it automatically syncs to the enterprise-catalog service. Related, the checks during enrollment to verify that a given course is part of an enterprise’s catalog(s) also make a call to the enterprise-catalog service as well.