0

I am trying to make request with a access token. But It returns an error. Okay, error explains it self, I newly created the access token and I am not sure why it's not working.

  function get_articles($instance_url, $access_token) {
        $url = $instance_url . "/services/data/v48.0/query?q=SELECT+Address__c,Area__c,ArticleMap__Latitude__s,ArticleMap__Longitude__s+FROM+Article__c+WHERE+ArticleMap__Latitude__s+!=+Null+AND+ArticleMap__Longitude__s+!=+Null";
        $curl = curl_init($url);
        curl_setopt($curl, CURLOPT_HEADER, false);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl, CURLOPT_HTTPHEADER,
                array("Authorization: Bearer $access_token",
                    "Content-type: application/json"));
        
        $json_response = curl_exec($curl);
        
        $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        echo "<pre>Status: $status";
    
        if ( $status != 200 ) {
            die("<pre>Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
        }
        
        echo "HTTP status $status getting available objects<br/><br/>";
    
        curl_close($curl);
    
        $response = json_decode($json_response, true);
    
        return $response;
        
    }

    $token = "code_of_token123123123";
    $url = "https://instance.my.salesforce.com/";
    $response = get_articles($url, $token);

    print_r($response);

And this the connected app image below. It's japanese though --sorry about that--. And I am using selected blue area's access token.. not the OAuth's consumer key.

enter image description here

Anyone has an idea what am I missing here?

3
  • I can read that the label next to the blue box you mentioned does say "access token" (no idea about the kanji), and it's in a section labeled [something] client [something] access token, but I'm afraid I'm not familiar with what configuration of connected app would provide a static access token like that.
    – Derek F
    Jul 9 '20 at 2:59
  • 2
    Thanks to Google lens, that's the "Initial access token for dynamic client registration" section. Maybe that'll help other people determine the problem here, but if not, I'll try to take a deeper look into it tomorrow.
    – Derek F
    Jul 9 '20 at 3:00
  • 1
    thank you for the comments... At the first comment, you mean the static access token usage is the problem? then should I get the token by OAuth login and use that? Jul 9 '20 at 3:05
2

Thanks to @Derek F for providing translation :)

The initial access token for client registration can only be used for OpenID client apps registration. That means you cannot use it to interact with regular REST API.

You have the following options :

  1. User one of the regular OAuth flows, where a user needs to provide access & refresh token.
  2. Use JWT OAuth flow if you only interact server to server.
1
  • I go with the 1st option. thank you. Jul 9 '20 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.