AnsweredAssumed Answered

Error adding assignment through API

Question asked by Ryan Arevalo on Jul 3, 2019
Latest reply on Jul 4, 2019 by Ryan Arevalo

Hello I am new to canvas and I am creating an external tool that creates modules and module items to be sent to canvas.

 

I am trying to add assignments to my module using php.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, '<canvas>/api/v1/courses/<courseid>/modules/<moduleid>/items');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "module_item[content_id]=1&module_item[title]=module item&module_item[type]=Assignment&module_item[position]=2&module_item[indent]=1&module_item[external_url]=<myexternalurl>");
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = 'Authorization: Bearer '. $token;
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
echo $result;
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);

 

Other module types like External Tool etc. are working except assignments and it always throw this message

{"message":"Could not find content"}

 

Need help with this

 

Outcomes