404 response when creating a course with the API - desire2learn

I am attempting to create a course with the API, and no matter how I tweak what I am sending I keep getting back the same 404 error. I am posting the following to /d2l/api/lp/1.4/courses/ in our test instance.
{
"Name":"STLR Course-112",
"Code":"STLR.112.201420",
"Path":"",
"CourseTemplateId":22462,
"SemesterId":22460,
"StartDate":"2014-05-07T12:00:00.000Z",
"EndDate":"2014-05-07T13:00:00.000Z",
"LocaleId":null,
"ForceLocale":false,
"ShowAddressBook":false
}

I can confirm with a test instance here that this API works with data almost identical to the block you provide here. POSTing a body like this (white space added for clarity):
{"CourseTemplateId": 8082,
"LocaleId": null,
"Code": "STLR.112.201420",
"Name": "STLR Course-112",
"Path": "",
"ShowAddressBook": false,
"EndDate": "2014-05-07T13:00:00.000Z",
"StartDate": "2014-05-07T12:00:00.000Z",
"ForceLocale": false,
"SemesterId": 6984}
Gets me a 200 with a response like this (white space added for clarity):
{"Identifier":"114119",
"Name":"STLR Course-112",
"Code":"STLR.112.201420",
"IsActive":true,
"Path":"/content/enforced/114119-STLR.112.201420/",
"StartDate":"2014-05-07T12:00:00.000Z",
"EndDate":"2014-05-07T13:00:00.000Z",
"CourseTemplate":{"Identifier":"8082",
"Name":"ExtensibilityTemplate",
"Code":"EXT-TMPL"},
"Semester":{"Identifier":"6984",
"Name":"Fall 2011",
"Code":"FA2011"},
"Department":{"Identifier":"8081",
"Name":"Extensibility",
"Code":"EXT"}
}
It appears to me that the only differences between my input block and yours are the IDs provided for course template and semester, so that I could hook the new course into my local test instance instead of the IDs for those orgunits in yours. Otherwise, it appears the input properties are identical.
Some things you could look at:
Ensure you're using the right Org Unit Id values for your course template and your semester
Ensure that your LMS is configured to enforce content paths for new org units: this should then provoke the LMS to auto-create the path for you when you create a course offering; if you don't have content path enforcement on, then you might have to instead specify a valid content path for your course offering on create, and passing in an empty string probably won't be a valid path, and thus you might get a 404 back because the API service handler "can't find the content path" you've specified.
Is there a particular message that comes back with the 404?

Related

Power Automate error when trying to add an attachment array from plumsail

I have a Plumsail form where a user can attach several pdf or word documents. In power automate I create an array of these documents and then attach the array to the "Start and wait for approval" action. When I run it, I get the error below:
The request failed. Error code: 'InvalidRequestContent'. Error
Message: 'The request content was invalid and could not be
deserialized: 'Could not find member 'ContentBytes' on object of type
'ApprovalsConnectorAttachment'.
I'm assuming you followed the How to send an email from Plumsail form with Power Automate Plumsail guide as it tells you to assign the HTTP GET file response to a property named ContentBytes.
While this will work with the Send an Email (V2) action (from the guide) the Start and wait for an approval action expects a property named content content.
To fix the problem append the following object to the array (note the contentproperty):
{
"name": #{items('Apply_to_each_2')?['file']},
"content": #{body('HTTP')}
}
or as an image:

How do I insert data to Astra DB using GraphQL API?

I am trying to follow this youtube tutorial.
I am getting stuck at inserting the first piece of data. Ania demonstrates it at 20.46 as follows:
mutation insertGenres {
action: insertreference_list(value: {label: "genre", value: "action"}) {
value{
value
},
}
When I try this, I get an error that says:
{
"errors": [
{
"message": "Validation error of type FieldUndefined: Field 'insertreference_list' in type 'Mutation' is undefined # 'insertreference_list'",
"locations": [
{
"line": 2,
"column": 3
}
],
"extensions": {
"classification": "ValidationError"
}
}
]
}
When I google the error, a lot of responses tell people to use mutations instead of queries - but I've started from a mutation. I would like to know how to resolve the error, but I'd also like to find the skills to improve my search strategy for finding answers.
When I look at the documentation for using GraphQL with DataStax, I see a different format to the write structure, which is as follows:
insertbook(value: bookInput!, ifNotExists: Boolean, options:
UpdateOptions): bookMutationResult
It has a colon and a fragment of text after it. It also explicitly states the ifNotExists: Boolean and options. I don't know if there may have been a change to how to use DataStax since the time Ania recorded the tutorial that means it is no longer a current demonstration of how to use the tool, or if there is an answer for this and I just haven't found it yet.
You didn't provide details of how you've configured your Astra DB for Ania's Netflix Clone tutorial so I'm going to assume that you've named your keyspace as netflix.
It seems as though you haven't followed the instructions correctly and have missed steps. I can replicate the error you reported if I skip at least one of the steps in the tutorial.
In step 5 of the tutorial, you needed to do the following:
✅ In graphQL playground, change tab to now use graphql. Edit the end of the URl to change from system to the name of your keyspace: netflix
✅ Populate HTTP HEADER variable x-cassandra-token on the bottom of the page with your token as shown below (again !! yes this is not the same tab)
Switch tabs
In order to insert data, you need to switch to the graphql tab.
If you try to insert the data in the graphql-schema tab, you will get the error you reported.
Set keyspace
You need to update the URI of your GraphQL playground in the graphql tab to use the keyspace name netflix instead of system. For example:
https://db_id-us-west1.apps.astra.datastax.com/api/graphql/system
change to:
https://db_id-us-west1.apps.astra.datastax.com/api/graphql/netflix
If you try to insert data into the system keyspace, you will get the error you reported because the reference_list table does not exist in that keyspace. Cheers!

Serverless - Change the content before deploy

I'm using Serverless for working with our aws lambda / appsync.
For Error Handling, we are keep erro code with message in a json file. The Codes will be unique. Something like this:
//error-code.json
{
"1"": { code: 1, message: "Invalid User Input"},
"2"": { code: 2, message: "Invalid Input"},
//... so on
}
This wil lbe deploy as layer and all the lambda will use it. Issue is we cannot use it in the resolve template. There are some of the resolver will be only template file. These template files cannot access the json file nor can access the layer. How can I use the error-code.json here?
Solution 1:
Manually write the error code in templates and make sure there are alway unique. Something like this:
#set(#errorInfo = {
"erroCode": "1",
"errorMessage": "Invalid Input"
})
$util.error("Invalid Input", "errorType", $ctx.arguments,#errorInfo)
Rejected: Becasue we have to manually check everytime for the unique of error code. In case of lot of template file, we cannot rely on it.
Solution 2:
Create a table with error code (unique) and error message. Use this table to send error from template.
Rejected: Because we use multiple app sync instance and they all connect to dirferent database. So we have to make this table in all database, and thus unique across the app-sync is not maintained.
Solution 3:
Write the placeholder in vtl where we want to send the error. Before Deploy, replace the placeholder with the actual code using pre-hook script, but not in the actual vtl file but in the generated package that serverless deploy. Does Serverless even such thing?
if your errors are all static, there is one more option for consideration.
You create one more file that holds all errors defined in Velocity.
$util.qr( $ctx.stash.put("errors", {}) ) $util.qr(
$util.qr( $ctx.stash.errors.put("ONE", { "code": 1, "message": "Invalid User
Input"} )
...
$util.qr( $ctx.stash.errors.put("TWENTY", { "code": 20, "message": "20th error description"} )
For every velocity resolver that throws errors, you inject pre-defined errors at the beginning of its request mapping's file. Whenever you want to throw an error, it's done by retrieving a pre-defined error from $ctx.stash
$util.error ( $ctx.stash.errors.ONE.message, $ctx.stash.errors.ONE.code )
The error file is generated from error-code.json, or manually typed again for simplicity. $ctx.stash is used because stash is accessible from everywhere in a resolver, including pipeline ones.

Gerrit Code Review - Retrieve file content from Change Edit

Has anyone successfully constructed the correct url to retrieve the file content from this endpoint?
All my attempts have resulted in a status 404.
The documentation is confusing in this link
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#get-edit-file
Below is the example it provides
GET /changes/{change-id}/edit/path%2fto%2ffile
this is data from gerrit.
{
"branch": "BR16516",
"change_id": "Ieb84eb99147fc39d3e117fe61eef8389d2f64611",
"change_number": "52490",
"change_revision": "2",
"file_name": "sql/BR16516-update-order-15102.sql",
"lines_inserted": 77,
"size_delta": 2041,
"status": "A"
}
I can't seem to provide a value for {change-id} and {'path%2fto%2ffile'} that gerrit recognises
The value I provided (see shown above) is the same value retrieved from /changes endpoint documented here
- https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes
This is the code example provided:
Retrieves content of a file from a change edit.
Request
GET /changes/myProject~master~I8473b95934b5732ac55d26311a706c9c2bde9940/edit/foo HTTP/1.0
In this example, the filename is 'foo' however the {change-id} introduces myProject~master~ and I tried substituting this for the relevant values for my project but with no luck.
If there are other endpoints that will give me plain text from the file in the branch, that will be good too.
I managed to get the file content from this end point
GET /changes/{change-id}/revisions/{revision-id}/files/{file-id}/content
change_id is the id from the change record
revision-id is the revision id from the change record
the change record is from the query changes end point
https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#list-changes

setting 'replace_original' to false while responding to Slack message action request doesn't work

Background:
I am using the python slack API (slackclient) to build an iterative sequence of data-gathering actions in ephemeral messages.
The core of this works fine. After processing the incoming request that contains the user's interaction with a set of message buttons (or menus), I respond immediately with a JSON body, as described in the "Responding right away" section of the official slack docs.
The problem:
Every response replaces the preceding message+attachments. In many cases, this is what I want, but there are situations where I want to add a response rather than replace the previous message.
Per the slack docs,setting replace_original to false should do just that. But the following code, snipped from my handling of a simple button click (for example), replaces the original button (and the text message to which it was attached):
r = {
'response_type': 'ephemeral',
'text': 'foo',
'replace_original': 'false'
}
log.debug("Returning: {}".format(json.dumps(r)))
resp = Response(response=json.dumps(r),
mimetype="application/json",
status=200)
return resp
I have tried this with and without the delete_original and response_type fields, with no change.
In short, it appears that in this case the replace_original field isn't doing anything at all; behavior is always as if it were set to 'true'.
I feel like I must be missing something here - any help is greatly appreciated.
Simple solution here: the slack API is expecting a boolean, not a string. So 'replace_original': 'false' in the above snippet ends up as {"response_type": "ephemeral", "text": "foo", "replace_original": "false"} after the json.dumps() call, which is invalid.
Instead, setting 'replace_original': False becomes {"response_type": "ephemeral", "text": "foo", "replace_original": false}, which then has the expected behavior

Resources