mrey2
(michael reynolds)
1
i am trying to get a token with a post on session. i have it formatted correctly
${auth_data}= Create Dictionary client_id=${CLIENTID} client_secret=${CLIENT_SECRET} headers=${header} grant_type=client_credentials
${response}= POST on Session token_session ${TOKEN_ENDPOINT} data=${auth_data}
and i keep getting
InvalidURL: Failed to parse: https://sdc-edifhirxpr:18088 headers=/oauth/token
why is it putting the endpoint in the header
You are the only person who can know what ${header}
contains, from here:
${auth_data}= Create Dictionary client_id=${CLIENTID} client_secret=${CLIENT_SECRET} headers=${header} grant_type=client_credentials
mrey2
(michael reynolds)
3
this is what should be in the header
${header}= Create Dictionary Content-Type=application/x-www-form-urlencoded
I think that ${header} should be a string and not a dictionary.
mrey2
(michael reynolds)
7
${header} Content-Type=application/x-www-form-urlencoded
*** Test Cases ***
Call API With Bearer Token
[Documentation] This test case calls an API endpoint with Bearer token authentication.
Step 1: Generate Bearer Token ${TOKEN_ENDPOINT}
Create Session token_session ${TOKEN_URL} headers=${EMPTY}
Log to Console header = ${header}
Log to Console endpoint = ${TOKEN_ENDPOINT}
${auth_data}= Create Dictionary client_id=${CLIENTID} client_secret=${CLIENT_SECRET} headers=${header} grant_type=client_credentials
Log to Console authdata = ${auth_data}
${response}= POST on Session token_session ${TOKEN_ENDPOINT} data=${auth_data} headers=${header}
${response}= POST on Session token_session ${TOKEN_ENDPOINT} data=${auth_data}
Should Be Equal As Integers ${response.status_code} 200
same error
InvalidURL: Failed to parse: https://sdc-edifhirxpr:18088 headers=/oauth/token
I am sure that there should be some examples in the Internet, but here is a working example:
*** Settings ***
Library RequestsLibrary
Library Collections
*** Variables ***
${base_URL} https://thetestingworld.com/
*** Test Cases ***
TC02_POST_request create new data
create session addData ${base_URL} verify=True
${body}= create dictionary first_name=A middle_name=B last_name=C date_of_birth=12/12/1990
${header}= create dictionary Content-Type=application/json
${response}= POST On Session addData /api/studentsDetails data=${body} headers=${header}
log to console ${response.status_code}
log to console ${response.content}
I am sorry for my previous comment, about ${header} be a String, which is not in my example.
rasjani
(not available)
9
If the error is correctly pasted here;
Failed to parse: https://sdc-edifhirxpr:18088 headers=/oauth/token
That means, the “headers” part is evaluated as part of the URL to Create Session
keyword, eg in here:
Create Session token_session ${TOKEN_URL} headers=${EMPTY}
You do not have enough spacaes between TOKEN_URL and headers … so they are evaluted as single argument to Create Session
2 Likes