Home>

logged in Oauth2.0 I try to take data from the transaction, but writes 401 [Detail]= > Invalid login or password)

I'm trying to take the data

$ QueryURL= 'https://xxxxx.amocrm.ru/api/v4/leads';
$ access_token= $ accesstoken;
    $ curl= curl_init ();
    CURL_SETOPT_ARRAY ($ CURL, Array (
        CURLOPT_SSL_VERIFYPEER= >
 0,
        Curlopt_post= >
 one,
        Curlopt_Header= >
 0,
        Curlopt_returntransfer= >
 one,
        Curlopt_url= >
 $ QueryURL,
        Curlopt_postfields= >
 $ QueryData,
    ));
    $ Result= Curl_exec ($ CURL);
    CURL_CLOSE ($ CURL);
    $ result= json_decode ($ result, 1);
    Print_R ($ result);

displays only Array ([Title]= > Unauthorized [Type]= > https://httpstatus.es/401 [Status]= > 401 [Detail]= > Invalid login or password)

wanted to output like this >

"Leads": [
    {
        "ID": 1184303,
        "Name": "New Test 2",
        "Price": 0,
        "Responsible_user_id": 6726247,
        "GROUP_ID": 0,
        "Status_ID": 40736470,
        "Pipeline_ID": 4379983,
        "loss_reason_id": null,
        "Created_BY": 0,
        "Updated_BY": 0,
        "Created_at": 1623860529,
        "Updated_at": 1623860529,
        "Closed_at": NULL,
        "closest_task_at": null,
        "IS_Deleted": False,
        "Custom_Fields_Values": NULL,
        "Score": NULL,
        "Account_id": 29544991,

Authorized through Oauth2.0 I am trying to take data from the transaction, but it writes -writes not authorized ...

InDevX2021-06-23 12:03:05
  • Answer # 1

    If Access_Token has already received (in your code, an incomprehensible string $ access_token= $ accesstoken; ) then you need to pass it in the title

    $ Headers= [
        'Authorization: Bearer'. $ accesstoken.
    ];
    $ curl= curl_init ();
    CURL_SETOPT_ARRAY ($ CURL, Array (
        CURLOPT_SSL_VERIFYPEER= >
     0,
        Curlopt_httpget= >
     1, //curlopt_httpget instead of curlopt_post
        Curlopt_Header= >
     0,
        Curlopt_returntransfer= >
     one,
        Curlopt_url= >
     $ QueryURL,
        Curlopt_httpheader= >
     $ Headers //Transfer Headers
    ));
    $ Result= Curl_exec ($ CURL);
    CURL_CLOSE ($ CURL);
    $ result= json_decode ($ result, 1);
    Print_R ($ result);
    

    Issues "Empty Query Body when POST Query Type

    Игорь Остапенко2021-06-23 12:03:05

    Curlopt_Httpget instead of curlopt_post and delete Curlopt_postfields

    InDevX2021-06-22 12:46:33