1

I'm working with a client's third party API and I was able to successfully post to their endpoint but with not much API experience I'm not sure how to go about working the PHP code snippet Postman renders to a WordPress hook, which is a Gravity Forms hook after form submission.

Looking at the snippet below I do see some instances that I feel like would not be beneficial to copy over like the Postman-Token and Cookie. I just can't find a way to get the basic authentication to work.

add_action( 'gform_after_submission_3', 'send_API', 10, 2 );
function send_API($entry, $form){
    $request = new HttpRequest();
    $request->setUrl('https://xxx.ddd.com/api/v1/leads');
    $request->setMethod(HTTP_METH_GET);

    $request->setHeaders(array(
      'cache-control' => 'no-cache',
      'Connection' => 'keep-alive',
      'content-length' => '231',
      'accept-encoding' => 'gzip, deflate',
      'cookie' => 'PSI_SESSION_ENT=ENT-bd0c3dsefe2b72d224aabec0d5991493f8de',
      'Host' => 'xxx.ddd.com',
      'Postman-Token' => '25b29855-79e0-4131ds-a099-3be03dsdc9eb6c6,7dc5458ddb-fc5a-4543-8ed5-5e3be5c883f3',
      'Cache-Control' => 'no-cache',
      'Accept' => '*/*',
      'User-Agent' => 'PostmanRuntime/7.13.0',
      'Authorization' => 'Basic Zm9ydGhlYV9hcGlAdGRjbWdtdDpGb3J0aGVhNTI5MjAxOSM=',
      'Content-Type' => 'application/json'
    ));

    $request->setBody('{
        "auth": {
            "type": "basic"
        },
        "requestId": "xx",
        "method": {
            "name": "name",
            "version": "r2",
            "params": {
                "propertyId": "xxx"
            }
        }
    }');

    try {
      $response = $request->send();

      echo $response->getBody();
    } catch (HttpException $ex) {
      echo $ex;
    }
}
Jose
  • 19
  • 2
  • Possible duplicate of [How do I make a request using HTTP basic authentication with PHP curl?](https://stackoverflow.com/questions/2140419/how-do-i-make-a-request-using-http-basic-authentication-with-php-curl) – zod Jun 18 '19 at 19:34
  • Why not just get the PHP cURL request that Postman generates for you, and use that? – DubVader Jun 18 '19 at 19:59

0 Answers0