In the salesforce REST API documentation, it tells how the system can give Oauth Tokens (https://code.exacttarget.com/apis-sdks/rest-api/v1/auth/requestToken.html ) But I don't see any documentation on how your system receives Oauth tokens when sending data.
I'm fairly new at combining OAuth with REST API, and so this is screwing with me a bit.
This code successfully gives me a token:
$exactTarget = 'https://auth.exacttargetapis.com/v1/requestToken';
$OAUTHarray = array('clientId' => 'SomethingGoesHere', 'clientSecret' => 'sshhhNowThatisASecret');
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $OAUTHarray ),
'header'=> "Content-Type: application/json\r\n" .
"Accept: application/json\r\n"
)
);
$context = stream_context_create( $options );
$result = file_get_contents( $exactTarget, false, $context );
$response = json_decode( $result );
I've outputted the data to make sure I was getting a valid token (and I was.) However, when trying to actually run commands, I can't get the tokens accepted.
This is my current follow-up code:
$exactTarget = 'https://www.exacttargetapis.com/contacts/v1/contacts';
$values = array ('name' => '' . $name, 'value' => '' . $email);
$items = array ('values' => $values);
$attributeSet = array ('items' => $items);
$dataset01 = array('contactKey' => '' . $email, 'contactId' => null, 'attributeSets' => $attributeSet);
$valuesArray = array($lastname, $firstname);
$itemsArray = array('values' => $valuesArray);
$dataset02 = array('name' => 'Email Democgraphics', 'items' => $itemsArray);
$finalData = array($dataset01, $dataset02);
if ($debug == true){
echo "<script>alert(" . $response->{"accessToken"} . ")</script>";
}
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode( $finalData ),
'header'=> "Content-Type: application/json\r\n" .
"Accept: application/json\r\n" .
"Authorization: Bearer " . $response->{"accessToken"} . "\r\n"
)
);
$context = stream_context_create( $options );
$result = file_get_contents( $exactTarget, false, $context );
$response2 = json_decode( $result );
So, what's wrong here, or what needs to be added?
$result
is being returned? Also, dump the response headers withvar_dump($http_response_header);
and add them to your question and it should be easier to answer.