So I was trying to follow the API documentation to save a contact with custom fields.
Contact is success created with no custom fields. But when I provide custom fields to it,I get error.
$postData = array( "name"=> trim($name), "email" => trim($email), "phone" => trim($phone), "mobile" => trim($phone), "custom_fields" => array("lb_module_id" => $member_id, "lb_user_id" => $user_id, "lb_module" => $module) ); $url = "https://".$this->domain.".freshdesk.com/api/v2/contacts"; $this->curl->setOpt(CURLOPT_USERPWD, $this->apiKey.":x"); $this->curl->setHeader("Content-Type", "application/json"); $this->curl->post($url, json_encode($postData)); if ($this->curl->error) { var_dump($this->curl->response); return 'Error: ' . $this->curl->errorCode . ': ' . $this->curl->errorMessage; } else { return $this->curl->response; }
The error var_dump
object(stdClass)[2533] public 'description' => string 'Validation failed' (length=17) public 'errors' => array (size=3) 0 => object(stdClass)[2484] public 'field' => string 'lbModuleId' (length=10) public 'message' => string 'Unexpected/invalid field in request' (length=35) public 'code' => string 'invalid_field' (length=13) 1 => object(stdClass)[2541] public 'field' => string 'lbUserId' (length=8) public 'message' => string 'Unexpected/invalid field in request' (length=35) public 'code' => string 'invalid_field' (length=13) 2 => object(stdClass)[2542] public 'field' => string 'lbModule' (length=8) public 'message' => string 'Unexpected/invalid field in request' (length=35) public 'code' => string 'invalid_field' (length=13)
can someone guide me, what am I doing wrong here.