14.6 C
New York
Monday, March 10, 2025

java – How can I retailer a worth as world variable from an API response and go it to a different API as parameter in Cucumber function file utilizing REST assured


I’m designing automation scripts utilizing the Cucumber BDD framework for REST APIs utilizing RestAssured. I’ve one API which generates the “Token” after which there may be one other API for order creation which requires this “Token” within the authorization parameter. Right here is my function file:

Function: Create Order API

  @Background:
  State of affairs Define: Generate Entry token With Legitimate Particulars
    Given Question param for request
      | grant_type         |
      | client_credentials |
    Given Primary Auth keys for request "" and ""
    When Construct request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_GET_AUTH_KEY"
#    And Set world "access_token" in "token"
    And Carry out "POST" request utilizing
    Then standing code is 200
    And  response incorporates "scope"
    Examples:
      | userName    | key |                                                                  
   | AWnCbuv9Bee0_6 | EMWowD696LqfznidhQ2RT_jZL2ys |

Now the response of the above API is as follows:

{
    "scope": "https://uri.pppaypal.com/providers/invoicing https://uri.pppaypal.com/providers/functions/webhooks",
    "access_token": "ALs1szFnv2TJ19Zf3vq",
    "token_type": "Bearer",
    "app_id": "APP-284543T",
    "expires_in": 311286,
    "nonce": "2022-05-31T03:41:41ZWs9dpOQ"
}

Now I want this “access_token” as within the “Create Order API” Authorization parameter with Bearer. The “Create Order API” function file is beneath:

 State of affairs: Confirm create order api utilizing legitimate auth
    Given Generate request
    And Construct request for baseurl "PAYPAL_BASE_URI" and endpoint "ENDPOINT_CREATE_ORDER_API"
    And Set header values as
      | Content material-Sort     | Authorization                                                                                            |
      | software/json | Bearer  |
    When Carry out "POST" request utilizing "FILE_PATH_ORDER_JSON"
    Then standing code is 201

How can I set “access_token” in “token” as a worldwide variable from the function file in order that I can use it anyplace on this function file utilizing the next step?

And Set world "access_token" in "token"

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles