I have redered /api-docs but seems there is no api for creating course. How can I create course using API via postman?
Hi @bhumi,
There is a simple technique you can use to answer such questions:
- Go to the Studio home page and click âNew Courseâ
- Right-click anywhere on the page and click âInspectâ or the equivalent in your browser
- Go to the âNetworkâ tab. Clear any entries currently there and enable âPreserve Logâ
- Fill out the New Course form and hit Create.
- Check the Network log to see the request:
POST /course/
{org: "OpenCraftX", number: "TEST", display_name: "A Test Course", run: "101"}
^ That is the API you can use to create a course.
@braden Api is giving me âCSRF verification failed. Request aborted.â error while calling from postman
I have passed X-CSRFToken:{{csrftoken}} in header and this line in tests section of postman
var xsrfCookie = postman.getResponseCookie(âcsrftokenâ); postman.setEnvironmentVariable(âcsrftokenâ, xsrfCookie.value);
still getting same error
Did you generate the CSRF token using the same credentials (e.g. OAuth bearer token or JWT) that youâre using to authenticate the request? Try using the /csrf/api/v1/token
API endpoint to retrieve the CSRF token, then submit it with X-CSRFToken
.
I have taken csrf toekn from browser cookie. I have called csrf/api/v1/token and itâs returning token but still getting 403 error
I have called
/csrf/api/v1/token without any payload and itâs returning
{
âcsrfTokenâ: ââ
}
I am passing this token in /couse api header like
X-CSRFToken:
but getting same error
@braden I have tried calling api using csrftoken from cookie and /course api is giving 200 status code but itâs not creating course inside the openedx
Are you checking for the course using the same user that created the course? What happens if you try creating the exact same course twice?
Basically, I suspect that itâs working but youâre not seeing the course due to permissions or something.
I am getting 200 status only so not getting if it is creating course or not. How can I fix the issue? Which permission I need to set? Also, response is html content. Itâs not giving created course id
Are you setting the Accept: application/json
header? Because that is required. This endpoint is shared by both HTML and JSON responses. See the code here for details.
Yes, I have set application/json in content-type header
Hi @bhumi ,
Did you find the solution, I am facing the same issue in postman.
CSRF verification failed. Request aborted.
can you please share the solution.
I got this api and I tried this in postman
First I was getting csrf token failed
Then I hit csrf api and got csrf token and added in the header section with X-CSRFToken and itâs value
Now getting url not found
Issue has been resolved you can use another openedx studio api api/v1/course_runs/
It will create course for you in studio. All you have to pass authentication access token in oauth2.0