Post

2 followers Follow
0
Avatar

Trouble creating an item with "category" and "app" fields

Trying to create a new Student Item using the following code:

$grade = settype($_POST['grade'],'integer');  // I did this because I got an error that said "Invalid value u'4': Must be Integral'."

** $teacher = settype($_POST['teacher'],'integer');**

** try { **

      $new_student = $this->api->item->create(STUDENT_APP_ID, **

*            array('fields' => *

**                  array(


                        "title" => $_POST['first']." ".$_POST['last'],

                        "first-name" => $_POST['first'],

                        "last-name" => $_POST['last'],

                       "teacher" => $teacher,

                       "grade" => $grade

                  )

            )

      );

** }**

Now I that I added the SETTYPE I get an error about it being boolean even though the console displays a number for both of them. Here's the output:

      error: "There was an error. The API responded with the error type 'invalid_value' and the message 'Invalid field 17766538 ('value'): Invalid value True: Must not be bool'."

      grade: 3

      message: "There was a problem adding the student to the account, please contact a site admin"

      success: false

      teacher: 19244880

So now I have "integer" values for both fields and they consider them boolean and I still can't create this item :(

Nick Worth Answered

Please sign in to leave a comment.

3 comments

0
Avatar

I may have just figured it out myself, basically same idea I had in mind when using SETTYPE() but instead I used the FLOATVAL() and that seemed to make it integral and acceptable

Nick Worth 0 votes
0
Avatar

Quick note: To cast strings as ints it's a little faster to type:

$grade = (int)$_POST['grade'];

 What type of field is the 'grade' field?

Andreas Haugstrup Pedersen 0 votes
0
Avatar

BTW, what does '_Must be Integral' _mean? I assumed it wanted an integer value, but Integral and Integer are two completely different things if Iam not mistaken.

Mike Knoop 0 votes