curlapigeeapigee-baasapigee127

How to get data from API using curl?


(I am new to curl and also apigee)

I am trying to get the Body data from API

"https://staging.api.pearson.com/content/scapi/urn:pearson:manifestation:014f333d-ceda-476f-81f2-d3d6c89ace42"

using curl with following command but unable to get any data than fault string

curl "https://staging.api.pearson.com/content/scapi/urn:pearson:manifestation:014f333d-ceda-476f-81f2-d3d6c89ace42"

Error that I am getting is :

{"fault":{"faultstring":"Failed to resolve API Key variable request.header.x-api key","detail":"errorcode":"steps.oauth.v2.FailedToResolveAPIKey"}}}

but when accessing the URL multiple times in Browser, I can able to get JSON data as desired

enter image description here

CURL woking code

curl "https://staging.api.pearson.com/content/scapi/urn:pearson:manifestation:014f333d-ceda-476f-81f2-d3d6c89ace42" -H "Accept:application/json"  -H "Accept-Encoding:gzip, deflate, sdch, br" -H "Accept-Language:en-US,en;q=0.8 " -H "Connection:keep-alive" -H "Host:staging.api.pearson.com" -H "X-ApiKey:7ij8zrLkCNR9DtAXx3KJ6yutoYnk4SAx" -H "X-PearsonSSOSession:AQIC5wM2LY4Sfczr6fmuhzvfN4dwnpK3c9K8tyduHkwg7sA.*AAJTSQACMDIAAlNLABQtNTk5Nzg3OTI1MTgxNTYxNjE3MAACUzEAAjAx*"

Kindly somebody suggest to get JSON data

Sorry I am new to curl and also apigee

Thanks


Solution

  • curl "URL" \
     -H "Accept: application/json" \
     -H "x-apikey: {need to pass your API key here}" \
     -H "Content-Type: application/octet-stream"
    

    Put your x-apikey in {need to pass your API key here}