Question

I'm trying to connect a linkedin signup to an addition to Zoho's Recruit API

When I use requestbin, It seems like it should work, but when I submit to Zoho, I get an error, could not parse data type.

This is where the info was on how to structure an xml post to zoho's api

https://www.zoho.com/recruit/add-records.html

Below is what my code looks like. Any advice on what I'm doing wrong?

<?php

$post_body = file_get_contents('php://input');
$application = json_decode($post_body);

//shortcodes

$firstname = $application->person->firstName;
$lastname = $application->person->lastName;
$city = $application->location->name;
$email = $application->person->emailAddress;
$headline = $application->person->headline;

  /*
   * XML Sender/Client.
   */
  // Get our XML. You can declare it here or even load a file.
  $xml_builder = "

                  <Candidates>
                  <row no=\"1\">
                  <FL val=\"First name\">{$firstname}</FL>
                  <FL val=\"Last name\">{$lastname}</FL>
                  <FL val=\"Contact address\">{$lastname}</FL>
                  <FL val=\"Email ID\">{$email}</FL>
                  <FL val=\"Current job title\">{$headline}</FL>
                  </row>
                  </Candidates>
                 ";




  // Initialize curl
    $curl = curl_init();



  $opts = array(
    CURLOPT_URL             => 'https://recruit.zoho.com/ats/private/xml/Candidates/addRecords?authtoken=#secrettoken&scope=recruitapi&duplicateCheck=1&xmlData={$xml_builder}',
    CURLOPT_RETURNTRANSFER  => true,
    CURLOPT_CUSTOMREQUEST   => 'POST',
    CURLOPT_POST            => 1,
    CURLOPT_POSTFIELDS      => $xml_builder,
    CURLOPT_HTTPHEADER  => array('Content-Type: text/xml','Content-Length: ' . strlen($xml_builder))                                                                       
  );

    // Set curl options
    curl_setopt_array($curl, $opts);

    // Get the results
    $result = curl_exec($curl);

    // Close resource
    curl_close($curl);

    echo $result;
    $fp = fopen('zoho.txt', 'w'); 
    fwrite($fp, $result); 
    fclose($fp);  



?>
Was it helpful?

Solution

You have to specify the POSTFIELDS names. And following the documentation you sent (https://www.zoho.com/recruit/add-records.html) you should remove the xmlData and duplicateCheck parameters from the URL, it's a POST only API.

I think you also should add the xml declaration (<?xml version='1.0' standalone='yes'?>)

So the code for the CURLOPT_POSTFIELDS definition would be the following:

$xml_builder = array(
              'duplicateCheck' => 1 ,
              'xmlData' => "
                           <?xml version='1.0' standalone='yes'?>
                           <Candidates>
                              <row no=\"1\">
                              <FL val=\"First name\">{$firstname}</FL>
                              <FL val=\"Last name\">{$lastname}</FL>
                              <FL val=\"Contact address\">{$lastname}</FL>
                              <FL val=\"Email ID\">{$email}</FL>
                              <FL val=\"Current job title\">{$headline}</FL>
                              </row>
                          </Candidates>"
);

And the $opts array should be like this:

$opts = array(
    CURLOPT_URL  =>'https://recruit.zoho.com/ats/private/xml/Candidates/addRecords?authtoken=#secrettoken&scope=recruitapi',
    CURLOPT_RETURNTRANSFER  => true,
    CURLOPT_CUSTOMREQUEST   => 'POST',
    CURLOPT_POST            => 1,
    CURLOPT_POSTFIELDS      => $xml_builder                                                                   
);

OTHER TIPS

Right now you have given

CURLOPT_URL             => 'https://recruit.zoho.com/ats/private/xml/Candidates/addRecords?authtoken=#secrettoken&scope=recruitapi&duplicateCheck=1&xmlData={$xml_builder}',

can u convert to single quote to double quotes as shown below and try once

CURLOPT_URL             => "https://recruit.zoho.com/ats/private/xml/Candidates/addRecords?authtoken=#secrettoken&scope=recruitapi&duplicateCheck=1&xmlData={$xml_builder}",
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top