-
Notifications
You must be signed in to change notification settings - Fork 9
/
curl.php
32 lines (25 loc) · 954 Bytes
/
curl.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
<?php
define( 'ACCESS_TOKEN', 'your-access-token-here' );
define( 'CLIENT_SECRET', 'your-client-secret-here' );
define( 'CONTENT_TYPE', 'application/json' );
define( 'ACCEPTS', 'application/json' );
define( 'ENDPOINT', 'https://api.fortnox.se/3/' );
function apiCall( $requestMethod, $entity, $body = null ){
$curl = curl_init( ENDPOINT . $entity );
$options = array(
'Access-Token: '. ACCESS_TOKEN .'',
'Client-Secret: '. CLIENT_SECRET .'',
'Content-Type: '. CONTENT_TYPE .'',
'Accept: '. ACCEPTS .''
);
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $curl, CURLOPT_HTTPHEADER , $options );
curl_setopt( $curl, CURLOPT_CUSTOMREQUEST , $requestMethod );
if( $requestMethod == 'POST' || $requestMethod == 'PUT' ){
curl_setopt( $curl, CURLOPT_POSTFIELDS, $body );
}
$curlResponse = curl_exec( $curl );
curl_close( $curl );
return $curlResponse;
}
?>