Zendesk REST API basics Follow

Comments

1 comment

  • Avatar
    Dariusz Andryskowski

    I have problem with authorization used Authentication OAuth 2https://developer.zendesk.com/rest_api/docs/zopim/auth when I get token I see information:


    {"error": "access_denied"}


    My steps:




    1. I create account https://www.zopim.com and I sign in to the panel dashboard.




    2. Copy from widget embed code and paste to head in html on (here is chat for client)http://order.localhost




    3. Create account consultant in https://www.zopim.com/account/api



      • I add Client Name: Robert

      • add redirectUrl: http://localhost/ When I save, I see Client ID and Client Secret




    4. I write test code in php to get authorization with curl




    $my script in php


     


    <?php


    $code = $_GET['code'];
    
    // Robert
    $clientId = "5lwYcZw1rhI2quE6js3J7QjwwKiaIOzMVosrci1uUdq2KaiswF";
    $clientSecret = "rxXu12dzEZexiYakWX7b5XYN2B1j4xNZJlzhherUAixZPKsBqN8YLM45iZUpyrLU";

    $redirectUrl = "http://localhost/";
    $dataPost = "grant_type=authorization_code&code=" . $code . "&client_id=" . $clientId . "&client_secret=" . $clientSecret . "&redirect_uri=" . $redirectUrl . "&scope=read%20write";

    $URL = "https://www.zopim.com/oauth2/token";
    $curl = curl_init();
    curl_setopt ($curl, CURLOPT_URL, $URL);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
    //curl_setopt($curl, CURLOPT_POSTFIELDS, "grant_type=authorization_code&code=" . $code . "&client_id=ajpwkP6hcqshNYzy8fS3yMKmWXv0tpGAQKPaqJAx5ZGVhjsmH2&client_secret=XSv0UFFumDh0NQ845dkdkQC1lX7I3ZYpUKAWow3zKQ7MwzaoWOFYiH11jYI7JXO3&redirect_uri=http://localhost/&scope=read%20write");
    curl_setopt($curl, CURLOPT_POSTFIELDS, $dataPost);

    if(curl_exec($curl) === false) {
    echo 'Curl error: ' . curl_error($curl);

    }

    $result = curl_exec ($curl);
    curl_close ($curl);
    var_dump($result);
    ?>


    This code I write in domain http://localhost (here consultant can talk with clinet from pagehttp://order.localhost)



    1. Next step I Open address url in browser


    https://www.zopim.com/oauth2/authorizations/new?response_type=code&client_id=5lwYcZw1rhI2quE6js3J7QjwwKiaIOzMVosrci1uUdq2KaiswF


    I see page zopim with information who sign in and two buttons:



    • Allow

    • Deny


    I click Allow



    1. Redirect me to http://localhost and I see {"error": "access_denied"}


    Why I have two domain?




    1. http://order.localhost -> here is page for client




    2. http:// localhost -> here is sytem crm for consultant. I want use zopim chat and integrate in my system crm, but I can't get token.




    Does anyone know why I have such an error

Please sign in to leave a comment.

Powered by Zendesk