Jump to content

php REST POST Help


chetwyn

Recommended Posts

Hi guys. I'm new to php and struggleing with the REST POST for some reason....

 

I need to insert a contact into this accouting system http://help.saasu.com/api/#toc-http-post  search for Example: Insert Contact.

 

the data strcutre looks like:

 

<?xml version="1.0" encoding="utf-8"?>
<tasks>
  <insertContact>
    <contact uid="0">
      <salutation>Mr.</salutation>
      <givenName>John</givenName>
      <familyName>Smith</familyName>
      <organisationName>Saasy.tv</organisationName>
      <organisationAbn>777888999</organisationAbn>
      <organisationPosition>Director</organisationPosition>
      <email>john.smith@saasy.tv</email>
      <mainPhone>            02 9999 9999      </mainPhone>
      <mobilePhone>            0444 444 444      </mobilePhone>
      <contactID>XYZ123</contactID>
      <tags>Gold Prospect, Film</tags>
      <postalAddress>
        <street>3/33 Victory Av</street>
        <city>North Sydney</city>
        <state>NSW</state>
<postCode>2000</postCode>
        <country>Australia</country>
      </postalAddress>
      <otherAddress>
        <street>111 Elizabeth street</street>
        <city>Sydney</city>
        <state>NSW</state>
<postCode>2000</postCode>
        <country>Australia</country>
      </otherAddress>
      <isActive>true</isActive>
      <acceptDirectDeposit>false</acceptDirectDeposit>
      <directDepositAccountName>John Smith</directDepositAccountName>
      <directDepositBsb>000000</directDepositBsb>
      <directDepositAccountNumber>12345678</directDepositAccountNumber>
      <acceptCheque>false</acceptCheque>
      <customField1>This is custom field 1</customField1>
      <customField2>This is custom field 2</customField2>
      <twitterID>Contact twitter id</twitterID>
      <skypeID>Contact skype id</skypeID>
    </contact>
  </insertContact>
</tasks>

 

 

I only have to insert 3 mandatory fields whcih are in the below code snipit im using but nothings working...

 

//set POST variables
$service_url = 'https://secure.saasu.com/webservices/rest/r1/tasks?wsaccesskey=<key removed>';


       $curl = curl_init($service_url);

$fileds = array(
'insertContact' => array(
	'contact' => array(
		'givenName' => urlencode('John'),
		'familyName' => urlencode('Smith'),
		'organisationName' => urlencode('Saasy.tv')
		)
	)
);

       curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
       curl_setopt($curl, CURLOPT_POST, true);
       curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
       $curl_response = curl_exec($curl);
       curl_close($curl);

       $xml = new SimpleXMLElement($curl_response);
   

 

 

Please help, I'm not sure what I'm doing wrong.... 

Link to comment
Share on other sites

According to your code $curl_post_data doesn't exist

curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);

 

And from the requirements it looks like the data needs to be in XML format. You have not got that far. All you have is a multidimension array stored in $fileds

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.