Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Brian Nguyen
    @brian3t
    hi
    I'm trying to make a call to corptools but it failed with 401

    $access_key = '';
    $secret_key = '';
    $base_url = 'https://api.corporatetools.com';
    $request_path = '/companies';
    $query_string = '?limit=1';
    $request_body = '';
    $header = json_encode([
    'typ' => 'JWT',
    'alg' => 'HS256',
    'access_key' => $access_key,
    ]);
    $payload = json_encode([
    'path' => $request_path,
    'content' => hash('sha256', $query_string . $request_body)
    ]);
    $e_header = strreplace(['+', '/', '='], ['-', '', ''], base64_encode($header));
    $e_payload = strreplace(['+', '/', '='], ['-', '', ''], base64_encode($payload));
    $signature = hash_hmac('sha256', $e_header . '.' . $e_payload, $secret_key, true);
    $e_signature = strreplace(['+', '/', '='], ['-', '', ''], base64_encode($signature));
    $jwt = $e_header . '.' . $e_payload . '.' . $e_signature;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $base_url . $request_path . $query_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch, CURLOPT_POSTFIELDS, $request_body);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_HTTPGET, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer $jwt",
    'Content-Type: application/json',
    'Accept: application/json'
    ]);

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);

    $result = curl_exec($ch);

    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // this results 0 every time
    $http_res_code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); // this results 0 every time
    if (curl_errno($ch)) {
    die ('Error:' . curl_error($ch));
    }
    if (! empty($http_res_code) && $http_res_code <> 200) die ("http response code: ${http_res_code}");
    curl_close($ch);
    echo '<pre>';
    echo json_encode(json_decode($result), JSON_PRETTY_PRINT);
    echo '</pre>';

    Corptools API
    @corporatetools

    Hey Brian, how are you doing? I was looking into your code this morning and it looks like the ? should be moved to a different line:

    ...
    $query_string = 'limit=1';
    ...
    curl_setopt($ch, CURLOPT_URL, $base_url . $request_path . '?' . $query_string);
    ...

    I attempted to add an offset to the query string: $query_string = 'limit=1&offset=1'; but that too causes a 401 error so I am now looking into that and will let you know if I find anything.

    Corptools API
    @corporatetools
    Good afternoon! I am happy to report that we deployed changes to our API that will make query string validation more forgiving. This means you should run into fewer 401 errors, but we still want you to reach out if you need assistance. Going forward, you should no longer need to add query_string to your payload content. Feel free to test it out and let me know if it works.
    Brian Nguyen
    @brian3t
    Thanks, it works now. Actually I still keep the ? in the query string like this
    $query_string = '?limit=1';
    ....
    curl_setopt($ch, CURLOPT_URL, $base_url . $request_path . $query_string);
    I think because you removed the need to add query string, it works much better now
    $payload = json_encode([
    'path' => $request_path,
    'content' => hash('sha256', $request_body)
    ]);
    Thank you very much. I'll start adding services using your API now.
    Corptools API
    @corporatetools
    Glad I could help. Reach out whenever you want
    Brian Nguyen
    @brian3t
    Hi, I'm able to query companies and services. But I'm still not able to query registered-agent-products. Could you please take a look? My sample code is:
    $access_key = '4399857f5067a649854bf3c61a344f5cb4bcbf5441ea7b036e0e7f6a90190b60cec71747e63091d0';
    $secret_key = '5843be58de4803d03387adc0407580e20c69f80e72742f841adcdaebc30b72b82acf006edc4d69db';
    $base_url = 'https://api.corporatetools.com';
    //$query_string = '?company_id=ee6a6fb1-7007-4511-a4e4-96749ae3bca6&limit=1';
    //$request_path = '/companies' . $query_string;
    $query_string = '?url=http://www.labyrinthinc.com';
    $request_path = '/registered-agent-products' . $query_string;
    $request_body = '';
    $header = json_encode([
        'typ' => 'JWT',
        'alg' => 'HS256',
        'access_key' => $access_key,
    ]);
    $payload = json_encode([
        'path' => $request_path,
        'content' => hash('sha256', $request_body)
    ]);
    $e_header = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($header));
    $e_payload = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($payload));
    $signature = hash_hmac('sha256', $e_header . '.' . $e_payload, $secret_key, true);
    $e_signature = str_replace(['+', '/', '='], ['-', '_', ''], base64_encode($signature));
    $jwt = $e_header . '.' . $e_payload . '.' . $e_signature;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $base_url . $request_path);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_HTTPGET, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, [
        "Authorization: Bearer $jwt",
        'Content-Type: application/json',
        'Accept: application/json'
    ]);
    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
    
    $result = curl_exec($ch);
    
    $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); // this results 0 every time
    $http_res_code = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); // this results 0 every time
    if (curl_errno($ch)) {
        die ('Error:' . curl_error($ch));
    }
    if (! empty($http_res_code) && $http_res_code <> 200) echo ("http response code: ${http_res_code}");
    curl_close($ch);
    echo '<pre>';
    echo json_encode(json_decode($result), JSON_PRETTY_PRINT);
    echo '</pre>';
    It always returns invalid website url . What should be the website url?
    Thanks