0

Could you please help me with this. I am struggling to get data with the Requests library.

import requests

payload = {'company':'USA', 'employeeid':'EMP1235'};

headers= {
          "Content-Type": 'application/json',
          'Access-Control-Allow-Origin': '*',
          'Authorization': "Bearer MyToken Pasted here",
        }

response = requests.get(
    'https://MyCompanyPath/getEmployeeDetails',
    params=payload ,
    headers= headers, 
)

print(response.json())
# or 
print(response.text)

Output

Please note the status is showing 200 with success. Following is the response content, but I see no data.

{'Parameters': [{'Name': 'company', 'Type': 'String'},
  {'Name': 'employeeId', 'Type': 'String'}],
 'Return': {'Name': 'return', 'Type': 'String'}}

But in Postman it is showing complete data OUTPUT like following:

"[{\"AccountNumber\":\"\",\"Address\":[{\"Address\":\"123 Coffee Street\\nSuite 300\\nRedmond, WA 98052 \\nUSA\",\"Description\":\"Contoso Entertainment System USA\",\"Primary\":\"No\",\"Purpose\":\"Business\"},{\"Address\":\"8367 Oak Ave\\nBlack Diamond, WA 98122 \\nUSA\",\"Description\":\"Home address\",\"Primary\":\"Yes\",\"Purpose\":\"Home\"}],\"RHRMEmplCategory\":\"\",\"AllowancesInformation\":[],\"AnniversaryDate\":\"/Date(-2208988800000)/\",\"ArabicName\":\"\",\"BankId\":\"\",\"BankLoan\":\"No\",\"BankName\":\"\",\"BirthDate\":\"/Date(-2208988800000)/\",\"ContactInformation\":[{\"ContactDetails\":\"theresa@contoso.com\",\"Description\":\"Work\",\"Extension\":\"\",\"Primary\":\"Yes\",\"Type\":\"Email\"},{\"ContactDetails\":\"425-555-5108\",\"Description\":\"Work\",\"Extension\":\"5108\",\"Primary\":\"Yes\",\"Type\":\"Phone\"}],\"ContractInformation\":[],\"Description\":\"\",\"EmplGender\":\"\",\"EmplMaritalStatus\":\"None\",\"EmployeeJobDetails\":[{\"Description\":\"Treasurer\",\"DescriptionText\":\"\",\"Function\":\"0200\",\"JobName\":\"Treasurer\",\"JobType\":\"Managers\"}],\"EmployeeJobResponsibility\":[{\"areaOfResponsibility\":\"Acctg & Finance\",\"Description\":\"Accounting and finance\",\"note\":\"\"}],\"EmployeeJobTask\":[{\"Description\":\"Financials/Accounting\",\"JobTask\":\"Accounting\",\"note\":\"\"}],\"EmployeeMedicalDetails\":[{\"fromDate\":\"/Date(-2208988800000)/\",\"InsuranceCompanyName\":\"\",\"InsuranceLevel\":\"\",\"InsuranceNumber\":\"\",\"InsuranceType\":\"None\",\"RelativeMedicalDetails\":[],\"toDate\":\"/Date(-2208988800000)/\"}],\"EmployoeeDocumentDetails\":[],\"HcmWorkerName\":\"rrrJayne\",\"IBAN\":\"\",\"NameAlias\":\"Theresa Jayne\",\"Nationality\":\"\",\"NSGEmplLocationId\":\"\",\"PaymentType\":\"\",\"RelativeInformation\":[],\"Religion\":\"\",\"StartDate\":\"/Date(-2208988800000)/\"}]"

Please make a note that JSON is returned as string from 3rd party application.

hc_dev
  • 8,389
  • 1
  • 26
  • 38
Chakra
  • 647
  • 1
  • 8
  • 16
  • 1
    Do you use the exact same payload in postman? It could be case sensitive so the API tells you what payload it accepts in the response (`employeeId` != `employeeid`) – HTF Apr 12 '21 at 17:27
  • Thanks a lot HTF. It did not resolve the problem, I still see the same output. But I am very surpised you realized it. After making exact case sensitive it still showed the same. I even tried with URLLIb3. – Chakra Apr 12 '21 at 17:35
  • What happens when you do a `curl`? – astrochun Aug 08 '21 at 20:26

0 Answers0