Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alecbw/8f5a0c41d2d5c8340c5eea16cb52804a to your computer and use it in GitHub Desktop.
Save alecbw/8f5a0c41d2d5c8340c5eea16cb52804a to your computer and use it in GitHub Desktop.
PHP implementation of calling the SourceStack API to pull active job posts, with several filter requirements applied
<?php
function fetch_jobs() {
$api_key = getenv("SOURCESTACK_KEY");
$data = array(
"export" => "caller",
"limit" => 100,
"fields" => ["post_url", "company_url", "job_name", "company_name", "job_location", "hours", "department", "seniority", "remote", "tags_matched", "tag_categories", "last_indexed", "post_html"],
"filters" => array(array("field" => "job_name", "operator" => "CONTAINS_ANY", "value" => ["SEO", "Content Market", "Digital Market"]))
);
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n" . "X-API-KEY: $api_key\r\n",
'method' => 'POST',
'content' => json_encode($data),
),
);
$context = stream_context_create($options);
$response = file_get_contents("https://sourcestack-api.com/jobs", false, $context);
return json_decode($response, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment