skip to Main Content

Trying to use curl to call api response.

The only documentation is this:
https://stage-sgf-partner-api.azurewebsites.net/api/swagger/ui#/Person/PartnerApi_Person_GetGolferInfoByGolfId

I have ClientId and Password to use for the server.

This is the error message from server.

"Failed to load API definition.

Errors

Fetch error
NetworkError when attempting to fetch resource. https://stage-sgf-partner-api.azurewebsites.net/api/swagger.json
Fetch error
Possible cross-origin (CORS) issue? The URL origin (https://stage-sgf-partner-api.azurewebsites.net) does not match the page (https://www.systemtest.the18club.se). Check the server returns the correct ‘Access-Control-Allow-*’ headers."

Any suggestions what can be wrong?

$username='xxxxx';
$password='xxxxx';
$URL='https://stage-sgf-partner-api.azurewebsites.net/api/swagger/ui#/Person/PartnerApi_Person_GetGolferInfoByGolfId=114973-122';
    
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result=curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);   //get status code
    
curl_close ($ch);

2

Answers


  1. Chosen as BEST ANSWER

    The people that built the API tells me the credentials should be send in the body. But this code below response "invalid credentials"

    $data = json_encode(array(
    'ClientId'  => 'xxxxx',
    'ClientSecret' => 'xxxxx'
    ));
        
    $URL='https://stage-sgf-partner-api.azurewebsites.net/api/v1/Authentication/Tokens';
        
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $URL);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        
    $result=curl_exec($ch);
    curl_close ($ch);
    print_r($result);
    

    What can be wrong?


  2. URL is wrong, you copied documentation link instead the API link which is like this: https://stage-sgf-partner-api.azurewebsites.net/api/v1/Persons/GetGolferInfoByGolfId?golfID=1

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search