How to use Ticket for getting response from the api

cancel
Showing results for 
Search instead for 
Did you mean: 
akash251998
Established Member II

How to use Ticket for getting response from the api

Jump to solution

I have a python code and using that python code i wanted to access: http://127.0.0.1:8080/alfresco/service/api/workflow-instances/

I am following one link https://docs.alfresco.com/5.2/concepts/dev-api-by-language-alf-rest-auth-with-repo.html where its mentioned that you need a ticket after that encode that ticket and use it to get the access.

Using the above link i am able to get Ticket and have encoded it but how i can use the ticket so that i can access that link using my python code.

Actually the url will give a json response and my requirement is to copy that json response and save it to my local system.

But while accessing the url http://127.0.0.1:8080/alfresco/service/api/workflow-instances/ its giving 401 Client Error: Unauthorized for url: http://127.0.0.1:8080/alfresco/service/api/workflow-instances/

 

Now i have the  ticket so what changes i should do in the url or using the ticket so that i can get access to that page and save the json content .

 

Any kind of help will be appreciated.

1 Solution

Accepted Solutions
akash251998
Established Member II

Re: How to use Ticket for getting response from the api

Jump to solution

Thanks @EddieMay  for again giving quick response as expected from you always.

I resolved that issue by myself only .

I wrote a python code, earlier it was giving 401 Unauthorized file error .. but i used authentication while accessing the url and it works fine.

 

import requests
from requests.auth import HTTPBasicAuth
from urllib.error import HTTPError

try:

response = requests.get('http://your_host:8080/alfresco/service/api/workflow-instances?state=Completed', auth=HTTPBasicAuth('your_username', 'your_password'))
response.raise_for_status()
# access JSOn content
jsonResponse = response.json()
print("Entire JSON response")
print(jsonResponse)

except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')

 

 

Note:The code is compatible with python version >=3

View solution in original post

3 Replies
EddieMay
Alfresco Employee

Re: How to use Ticket for getting response from the api

Jump to solution

Hi @akash251998 

Have you had a chance to look at the API tutorial series? Also, have you tried using Postman for testing before attempting to implement with Python?

Also, have you looked at Alfresco API client libraries in Python?

HTH,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!
akash251998
Established Member II

Re: How to use Ticket for getting response from the api

Jump to solution

Thanks @EddieMay  for again giving quick response as expected from you always.

I resolved that issue by myself only .

I wrote a python code, earlier it was giving 401 Unauthorized file error .. but i used authentication while accessing the url and it works fine.

 

import requests
from requests.auth import HTTPBasicAuth
from urllib.error import HTTPError

try:

response = requests.get('http://your_host:8080/alfresco/service/api/workflow-instances?state=Completed', auth=HTTPBasicAuth('your_username', 'your_password'))
response.raise_for_status()
# access JSOn content
jsonResponse = response.json()
print("Entire JSON response")
print(jsonResponse)

except HTTPError as http_err:
print(f'HTTP error occurred: {http_err}')

 

 

Note:The code is compatible with python version >=3

EddieMay
Alfresco Employee

Re: How to use Ticket for getting response from the api

Jump to solution

Hi @akash251998 

Thanks for reporting back how you resolved your issue - that's really helpful to other users.

Kind regards,

Digital Community Manager, Alfresco Software.
Problem solved? Click Accept as Solution!