API add topic

Options
Steve.M.925
Steve.M.925 Posts: 1 🌱

This is driving me mad

I can add a URL topic, no problem.

However, adding a FILE topic is proving to be impossible, I always get a 400 error.

I tried postman, python, and curl.

Trying to stay as close to example in the documentation as possible. I know the URL is not correct for my instance.

curl --http1.1 --request POST \                                                                                              ⇄
--url https://{{d2lhost}}/d2l/api/le/{{version}}/{{courseid}}/content/modules/{{moduleid}}/structure/ --header 'Content-Type: multipart/mixed; boundary=xxBOUNDARYxx' --data '--xxBOUNDARYxx
Content-Type: application/json {"IsHidden": false, "IsLocked": false, "ShortTitle": "Test", "Type": 1,
"DueDate": null, "Url": "/content/extensibility/EXT-104/file.txt",
"StartDate": null, "TopicType": 1, "EndDate": null, "Title": "Test topic
content"}
--xxBOUNDARYxx
Content-Disposition: form-data; name=""; filename="file.txt"
Content-Type: text/plain This is a sample text file
with some text content.
--xxBOUNDARYxx--'

I removed the authorization from the curl.

I always get back:

{'type': 'http://docs.valence.desire2learn.com/res/apiprop.html#invalid-parameters', 'title': 'Invalid Parameters', 'status': 400, 'detail': 'Request has missing or invalid parameters.'}

Tagged:

Answers

  • Steve.B.446
    Steve.B.446 Posts: 76
    Options

    You're using a POST request, but the documentation specifies a GET request, but I suspect it's not going to be that simple!

    This looks to be formed the same way as an example I have here which does work, except I've got the data all on one line with \r\n style linebreaks, which might be worth a try.

    My only other observation is that I'm not familiar with /content/extensibility as a file path within Brightspace, but that could be a site-specific configuration at your end or you're using a bit of functionality that I'm not familiar with.