# InvalidURL: Failed to parse: https://sdc-edifhirxpr:18088 headers=/oauth/token

**URL:** <https://forum.robotframework.org/t/invalidurl-failed-to-parse-https-sdc-edifhirxpr-18088-headers-oauth-token/6230>\
**Category:** RequestsLibrary\
**Created:** [20 September 2023 18:22 UTC](https://forum.robotframework.org/t/invalidurl-failed-to-parse-https-sdc-edifhirxpr-18088-headers-oauth-token/6230 "2023-09-20T18:22:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrey2](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mrey2](https://forum.robotframework.org/u/mrey2)\
**Post date:** [20 September 2023 18:22 UTC](https://forum.robotframework.org/t/invalidurl-failed-to-parse-https-sdc-edifhirxpr-18088-headers-oauth-token/6230/1 "2023-09-20T18:22:36Z")

</div>

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](https://sdc-edifhirxpr:18088) headers=/oauth/token

why is it putting the endpoint in the header

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [20 September 2023 19:56 UTC](https://forum.robotframework.org/t/invalidurl-failed-to-parse-https-sdc-edifhirxpr-18088-headers-oauth-token/6230/2 "2023-09-20T19:56:51Z")

</div>

> [@mrey2](#):
>
> why is it putting the endpoint in the header

You are the only person who can know what `${header}` contains, from here:

```python
${auth_data}= Create Dictionary client_id=${CLIENTID} client_secret=${CLIENT_SECRET} headers=${header} grant_type=client_credentials

```

---

<div class="post-metadata">

**Author:** ![mrey2](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mrey2](https://forum.robotframework.org/u/mrey2)\
**Post date:** [20 September 2023 19:58 UTC](https://forum.robotframework.org/t/invalidurl-failed-to-parse-https-sdc-edifhirxpr-18088-headers-oauth-token/6230/3 "2023-09-20T19:58:33Z")

</div>

this is what should be in the header

${header}= Create Dictionary Content-Type=application/x-www-form-urlencoded

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [20 September 2023 20:12 UTC](https://forum.robotframework.org/t/invalidurl-failed-to-parse-https-sdc-edifhirxpr-18088-headers-oauth-token/6230/4 "2023-09-20T20:12:53Z")

</div>

I think that ${header} should be a string and not a dictionary.

---

<div class="post-metadata">

**Author:** ![mrey2](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mrey2](https://forum.robotframework.org/u/mrey2)\
**Post date:** [20 September 2023 20:59 UTC](https://forum.robotframework.org/t/invalidurl-failed-to-parse-https-sdc-edifhirxpr-18088-headers-oauth-token/6230/7 "2023-09-20T20:59:18Z")

</div>

${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](https://sdc-edifhirxpr:18088) headers=/oauth/token

---

<div class="post-metadata">

**Author:** ![HelioGuilherme66](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/helioguilherme66/32/34_2.png) [@HelioGuilherme66](https://forum.robotframework.org/u/HelioGuilherme66)\
**Post date:** [20 September 2023 21:39 UTC](https://forum.robotframework.org/t/invalidurl-failed-to-parse-https-sdc-edifhirxpr-18088-headers-oauth-token/6230/8 "2023-09-20T21:39:34Z")

</div>

I am sure that there should be some examples in the Internet, but here is a working example:

```plaintext
***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.

---

<div class="post-metadata">

**Author:** ![rasjani](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@rasjani](https://forum.robotframework.org/u/rasjani)\
**Post date:** [22 September 2023 09:48 UTC](https://forum.robotframework.org/t/invalidurl-failed-to-parse-https-sdc-edifhirxpr-18088-headers-oauth-token/6230/9 "2023-09-22T09:48:36Z")

</div>

If the error is correctly pasted here;

> Failed to parse: [https://sdc-edifhirxpr:18088](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:

```python
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`
