2017-05-15 12 views
1

私は文書のこの部分に従っています:http://developers.marketo.com/rest-api/assets/tokens/と私はいつも次のエラーが表示されます:フィールドは空にすることはできません。Marketo REST APIアセットトークンは機能しますか?

誰かにそれを働かせてもらえますか?

public function create_token($folder_id,$name,$content,$folder_type = 'Program') 
{ 
    $folder_id = intval($folder_id); 
    $endpoint = 'rest/asset/v1/folder/'.$folder_id.'/tokens'; 
    $body = new stdClass(); 
    $body->folderType = $folder_type; 
    $body->name = $name; 
    $body->type = 'rich text'; 
    $body->value = $content; 
    $body_encoded = json_encode($body); 

    echo $url = $this->url . $endpoint . ".json?access_token=" . self::$token; 

    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: x-www-form-urlencoded')); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $body_encoded); 
    $response = curl_exec($ch); 
    curl_close($ch); 
    return json_decode($response); 
} 

Content-Typeヘッダの理由はMarketoからの提案だった:あなたがする必要はありません

object(stdClass)#1934 (4) { 


["success"]=> 
    bool(false) 
    ["warnings"]=> 
    array(0) { 
    } 
    ["errors"]=> 
    array(4) { 
    [0]=> 
    object(stdClass)#1935 (2) { 
     ["message"]=> 
     string(20) "name cannot be null." 
     ["code"]=> 
     string(3) "701" 
    } 
    [1]=> 
    object(stdClass)#1936 (2) { 
     ["message"]=> 
     string(20) "type cannot be null." 
     ["code"]=> 
     string(3) "701" 
    } 
    [2]=> 
    object(stdClass)#1937 (2) { 
     ["message"]=> 
     string(101) "Token type is either null, blank or invalid. Please refer to the documentation for valid token types." 
     ["code"]=> 
     string(3) "701" 
    } 
    [3]=> 
    object(stdClass)#1938 (2) { 
     ["message"]=> 
     string(21) "value cannot be null." 
     ["code"]=> 
     string(3) "701" 
    } 
    } 
    ["requestId"]=> 
    string(16) "11d1#15b49284636" 
} 

答えて

0

:これは私が取得しておくの要求からの回答であるhttps://www.screencast.com/t/CL5ZtPo1o

トークンフィールドをJSONオブジェクトとして投稿する:json_encode($body)
フィールドはリクエストパラメータまたは通常のフォームとして渡されます

これは私のためにうまく機能して要求:この場合

POST https://123-FOO-456.mktorest.com/rest/asset/v1/folder/1039/tokens.json?value=TestTokenValue&folderType=Program&name=TestToken&type=text 

、あなたはまた、コンテンツタイプに私はPHP devのではないよContent-Type: x-www-form-urlencoded

を指定する必要はありませんが、例のために、ここで見ることができますフォームデータの投稿方法 - PHP + curl, HTTP POST sample code?

関連する問題