I'm trying to call the EPM API using Python Requests, but it doesn't work. What is wrong with the script below?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

I'm trying to call the EPM API using Python Requests, but it doesn't work. What is wrong with the script below?

L1 Bithead

I'm trying to call the EPM API using Python Requests, but it doesn't work. What is wrong with the script below? I created it with reference to the following document.

 

https://docs.cyberark.com/EPM/23.11.0/en/Content/WebServices/GetDetailedRawEvents.htm

 

The Python script is below.

 

#####################################

import requests

import json

 

token = "<Token that have been researched in advance>"

setID = "<SetID that have been researched in advance>"

 

url = "https://jp.epm.cyberark.com/EPM/API/Sets/" + setID + "/Events/Search"

headers = {"Content-Type": "application/json", "Authorization": "basic " + token}

data = {"filter": "fileName CONTAINS \"notepad++\""}

 

res = requests.post(

  url,

  headers = headers,

  json = data,

  verify = False

)

 

print(res.status_code)

print(res.text)

#####################################

 

When I run the above, the following will be displayed.

 

500

[{"ErrorCode":"EPM000001E","ErrorMessage":"Internal Error."}]

 

1 accepted solution

Accepted Solutions

L1 Bithead

Hi everyone,

This problem solved! It was the server URL that was the problem.

 

Incorrect:

url = "https://jp.epm.cyberark.com/EPM/API/Sets/" + setID + "/Events/Search"

 

Correct:

url = "https://jp153.epm.cyberark.com/EPM/API/Sets/" + setID + "/Events/Search"

 

Actually, there were no other problems other than the above.

 

To explain, "jp.epm.cyberark.com" is the address of the Dispatcher server, and this API will not work unless it is a server after being dispatched.

View solution in original post

16 REPLIES 16

L7 Applicator

Hi @Koichiro Ota​ I see the following three issues in the script.

 

 

1.Indentation Issue:Python relies on indentation to define blocks of code. Ensure proper indentation throughout the script.

 

2.Authorization Header:The “Authorization” header should use the word “Basic” instead of “basic” in the authorization scheme

 

3.Quotes in the Data Payload:

Ensure consistent use of quotes in the data payload. In the provided script, double and triple double-quotes are used. Stick to one type for consistency.

 

L7 Applicator

Hi @Koichiro Ota​ Please check whether the following updated script helps

 

 

import requests

import json

 

token = "<Token that has been researched in advance>"

setID = "<SetID that has been researched in advance>"

 

url = "https://jp.epm.cyberark.com/EPM/API/Sets/" + setID + "/Events/Search"

headers = {"Content-Type": "application/json", "Authorization": "Basic " + token} 

data = {"filter": 'fileName CONTAINS "notepad++"'}

 

res = requests.post(

  url,

  headers=headers,

  json=data,

  verify=False

)

 

print(res.status_code)

print(res.text)

L7 Applicator

Hi. If you are happy with the above answer, can you please mark it as ‘Best Answer’ ?

L1 Bithead

Hi @Malhar Vora​,

Thank you very much. But it didn't work well.

 

#####################################

import requests

import json

 

token = "<Token that have been researched in advance>"

setID = "<SetID that have been researched in advance>"

 

url = "https://jp.epm.cyberark.com/EPM/API/Sets/" + setID + "/Events/Search"

headers = {"Content-Type": "application/json", "Authorization": "Basic " + token}

data = {"filter": 'fileName CONTAINS "notepad++"'}

 

res = requests.post(

  url,

  headers = headers,

  json = data,

  verify = False

)

 

print(res.status_code)

print(res.text)

#####################################

 

The result of running the above script is below.

 

500

[{"ErrorCode":"EPM000001E","ErrorMessage":"Internal Error."}]

L7 Applicator

Hi @Koichiro Ota​ Just wanted to check, are you able to use Postman to test the authentication to EPM API and see if that is successful?

L1 Bithead

Hi @Malhar Vora​  , Thank you for your reply.

Of course, the authentication is successful. If authentication fails, a message like the one below will be displayed.

 

401

[{"ErrorCode":"EPM000003E","ErrorMessage":"Your session has expired and your user has been disconnected."}]

 

By the way, Mr. Malhar, may I ask you a question? Do you have the environment to try these?

L7 Applicator

Hi @Koichiro Ota​ Sorry I don’t have access to EPM portal to be able to validate it

L1 Bithead

Is that so. Thank you very much.

Is there anyone else besides me who can try it?

L5 Sessionator

Hi @Koichiro Ota​,

 

Did you try without filter (fileName CONTAINS \"notepad++\)?

 

Thanks,

Tamir

L1 Bithead

Hi @Tamir Hochman​ ,

thank you for the advice.

Actually, I have already tried it and executed the following script.

 

#####################################

import requests

import json

 

token = "<Token that have been researched in advance>"

setID = "<SetID that have been researched in advance>"

 

url = "https://jp.epm.cyberark.com/EPM/API/Sets/" + setID + "/Events/Search"

headers = {"Content-Type": "application/json", "Authorization": "Basic " + token}

 

res = requests.post(

  url,

  headers = headers,

  verify = False

)

 

print(res.status_code)

print(res.text)

#####################################

 

The above result is below.

 

500

[{"ErrorCode":"EPM000001E","ErrorMessage":"Internal Error."}]

Hi @Koichiro Ota​,

 

I can share that we tested it internally, and everything worked as expected.

To assist, we will need to see a recording of how exactly you perform the login and query the problematic API.

 

Can you please open a support case so we can analyze the logs and understand the root cause?

Link: https://community.cyberark.com/s/Submit-a-Case

 

Thanks,

Tamir

L1 Bithead

Hi @Tamir Hochman​ ,

Thank you very much. I tried to open a support case, but the screen below keeps showing up. Even if I press the continue button, there is no response.

Field_Content_versions_oct20__068Ht00000TjpWDIAZ.png

Hi @Koichiro Ota​,

 

Following on the script. You should try with PostMan and verify the functionality.

 If it works you need to debug the script as the service is working as expected.

 

Regarding the support ticket:

To raise a support ticket, users who should have access to support tickets will navigate to the main page of the Technical Community > Click on the 'Requests' Tab > "Cases" > "New Case" button (located on the right side of the screen).

Using direct links to the community is not recommended, as URLs may often change and become outdated (as in your case, as you've listed an old unused URL).

 

If you don't have access to raise or review support tickets. Please contact [email protected] or your CyberArk representative for further assistance if you require such access.

 

In the meantime, if you need additional assistance or would like to explore other support options, please visit the CyberArk official website at: https://www.cyberark.com/services-support/technical-support-contact/

 

I hope your issue will be resolved soon!

 

Thanks,

Tamir

I got it. thank you.

  • 1 accepted solution
  • 631 Views
  • 16 replies
  • 0 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!