client.request() secure parameter - Using the response



投稿日時:2022年3月25日

Hello Community, 

I have following flow:

1) Defined a client id and secret in the manifest.json

2) client_secret parameter is defined as secure type in the manifest.json

3) Used the client.request() and {{setting.client_id}} syntax to fetch the secure type parameter value

4) The secure type parameter is used to fetch an access token using an API call 

5) Now I need to access the access token from the response object to call another API. However this fails. When I try to access the response object from step 4 it returns undefined

Following are my 2 calls 

const oAuthResponse = await client.request({
      type: 'POST',
      url: "https://api-m.paypal.com/v1/oauth2/token",
      contentType: 'application/json',
      headers: { "Authorization": "Basic {{setting.client_secret}}", "Accept": "application/json"},
      data: 'grant_type=client_credentials',
      cors: false,
      secure: true,
      httpCompleteResponse: true
    }
  ).then(function(data) {
      console.log('...oAuthResponse', data);
      return data['access_token'];
  });
const fetchTransResponse = await client.request({
      type: METHOD_GET,
      url: url,
      contentType: 'application/json',
      headers: { "Authorization": "Bearer "+oAuthResponse},
      cors: false,
      secure: true,
      httpCompleteResponse: true
    }
  ).then(function(data) {
      console.log(data);
      return data;
  });

Please note that the second call works absolutely fine when I hardcode the access token. 

Also the first call is working fine. I have validated that. 

 


0

1

0件のコメント

      サインインしてコメントを残します。

      お探しのものが見つかりませんか?

      新規投稿