The CreatorCon Call for Content is officially open! Get started here.

Getting 404 when trying to call a rest api

Ariel Lumbroso
Tera Contributor

i calling an api endpoint to get an oauth token back. i need to pass through the body the : username,password and grant_type.

I am following exactly what works for me in a powershell script but i keep getting "invalid grant type" when trying to do via a rest message in service now.

this is the powershell working and returning a valid token.

$tokenRoute = "https://tenant.com.au//oauth2/token"
$creds = @{
    username = "myusername"
    password = "Mypassword"
    grant_type = "password"
}  
$token = ""
$response = Invoke-RestMethod $tokenRoute -Method Post -Body $creds
$token = $response.access_token;
 
this is what I am doing in service now which returns 404 (invalid grant type):
 
find_real_file.png
1 ACCEPTED SOLUTION

Palak Gupta
Tera Guru

Hi there!

Update your method as per below screenshot and try to test

find_real_file.png

and in content mention like this without this"{}"

grant_type=password&username=myusername&password=Mypassword

Please mark my answer correct and helpful if this resolves your issue.
Regards,
Palak

 

View solution in original post

2 REPLIES 2

Palak Gupta
Tera Guru

Hi there!

Update your method as per below screenshot and try to test

find_real_file.png

and in content mention like this without this"{}"

grant_type=password&username=myusername&password=Mypassword

Please mark my answer correct and helpful if this resolves your issue.
Regards,
Palak

 

Thanks, this helped me as well.

The main problem I had was that I was provided from workday side with few details, but was really missing how the structure should looks like in the header and body of the rest message in ServiceNow.

At the end my POST message to get token looks like below with basic authentication where I needed to use in user name / pwd client id and client secret

 

With that POST call Im getting token that I use in next message GET to get data from source system

 

PetrPastuszek1_0-1702622586776.png

 

Second GET Message to get data from source system using new TOKEN from first post message

PetrPastuszek1_1-1702622806038.png

 

 

One question to all, maybe someone can answer.

If I have first POST message, second GET, can I pass from post message to GET message value of new token directly via variable substituion or somehow else without need to call REST message via script?

- directly in the interface above (images above)

 

/Petr