-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproca-actions.php
66 lines (59 loc) · 1.6 KB
/
proca-actions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
$username : emailid of proca account
$password : account pass
*/
$username ="Add Email ID";
$password = 'Add Password';
$auth= base64_encode("$username:$password");
$service_url = "https://api.proca.app/api";
$query1 = <<<'GRAPHQL'
query GetCampaigns($name:String) {
org(name:$name) {
campaigns {
name
title
externalId
}
}
}
GRAPHQL;
$query2 = <<<'GRAPHQL'
Mutation change($orgName:String!,$campaignName:String!,$title:String!) {
upsertCampaign(orgName:$orgName,input: {
name:$campaignName,
title:$title,
actionPages:[
{name:"beeeci/counter",locale:"en",extraSupporters:632154, live: true},
]
})
{
id
}
}
GRAPHQL;
function graphql_query(string $endpoint, string $query, array $variables = [], string $operationName, string $token = null): array
{
$headers = ['Content-Type: application/json'];
$data= array();
if (null !== $token) {
$headers[] = "Authorization: Basic $token";
}
if (false === $data = @file_get_contents($endpoint, false, stream_context_create([
'http' => [
'method' => 'POST',
'header' => $headers,
'content' => json_encode(['query' => $query, 'variables' => $variables, 'operationName'=>$operationName]),
]
]))) {
$error = error_get_last();
throw new \ErrorException($error['message'], $error['type']);
}
// var_dump($data);
return json_decode($data, true);
}
$data =graphql_query($service_url, $query2, ["campaignName"=>'test',"title"=>'test',"orgName"=>'campax'],'change',$auth);
echo '<pre>';
print_r($data);
echo '</pre>';
?>