[SalesForce] ExactTarget REST API – Getting issues with /contacts/ and /campaigns/

I'm new with ExactTarget APIs, I'm using Php curl to request the ExactTarget REST API.

Basically, I tried to create a contact:

 $array = array(
    'contactKey' => 'test@test.fr',
    'contactId' => null,
    'attributeSets' =>  array(
        'name' => 'Email Addresses',
        'items' => array('values' => array('name' => 'Email Address', 'value' => 'test@test.fr'))
    ),
  );
  $postfield = json_encode($array);
  var_dump(json_decode($postfield));
  $curl = curl_init( "https://www.exacttargetapis.com/contacts/v1/contact" );
  curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $accessToken ) );
  curl_setopt( $curl, CURLOPT_POST, true );
  curl_setopt( $curl, CURLOPT_POSTFIELDS,  $postfield );
  curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE);
  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);

But this fall in a 404 error:

 object(stdClass)[2]
  public 'documentation' => string 'https://code.docs.exacttarget.com/rest/errors/404' (length=49)
  public 'errorcode' => int 404
  public 'message' => string 'Not Found' (length=9)

Could you please help me ? What am I doing wrong ? I tried to change my $array, even with an empty array I always get this message.


Otherwise, I tried to create a campaign the same way:

$array = array(
      'name' => 'Testapi',
      'description' => 'description try',
      'campaignCode' => 'ooiampaign',
      'color' => '0000ff',
      'favorite' => false
      );
  $postfield = json_encode($array);
  $curl = curl_init( "https://www.exacttargetapis.com/hub/v1/campaigns" );
  curl_setopt( $curl, CURLOPT_HTTPHEADER, array( 'Authorization: Bearer ' . $accessToken ) );
  curl_setopt( $curl, CURLOPT_POST, true );
  curl_setopt( $curl, CURLOPT_POSTFIELDS,  $postfield );
  curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE); // important (testé en Local wamp) afin de ne pas vérifier le certificat SSL
  curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);

I got a successful result but the name, the campaignCode and the description are empty in the campaign created.

If someone could help me with those 2 issues, that would be really great.

Thank you, and sorry if I misspelled something, English is not my native language.

Best Answer

I spoke with the Salesforce support team. The REST /contacts endpoint is not a direct replacement for the SOAP API's functionality to add and modify Subscibers to lists. Currently the REST API does not support this. The contacts if for other salesforce functionality that if you don't have enabled (you're just using ET for example) will 404. So, to work with Subscribers you must use the ET SOAP api.

ET has created a set of SDKs which abstracts and combines both the REST and the SOAP API functionality--available in several languages such as java, ruby, php. https://code.exacttarget.com/apis-sdks/fuel-sdks/

Yup this is crazy. Yup it smells of entropy.

I think it's directly tied to the challenges they're having absorbing ET into Salesforce why so long after the merger they don't have a cohesive single API solution.

Related Topic