[Spce-user] Create invoice via API: No response via http GET
Irina Peshinskaya
ipeshinskaya at sipwise.com
Fri Jan 25 09:55:02 EST 2019
Dear Thomas,
After creation invoice you need to downloaded generated invoice using call:
curl -i -X GET -H 'Connection: close' -H 'Accept: application/pdf'
--user administrator:administrator -k
'https://127.0.0.1:1443/api/invoices/3' > /tmp/invoice_3.pdf
Where 3 is a id of the newly generated invoice.
You can get id from the Location header of the response.
In console it looks as:
root at sp1:~# curl -i -X POST -H 'Connection: close' -H 'Content-Type:
application/json' --user administrator:administrator -k
'https://127.0.0.1:1443/api/invoices/' --data-binary '{ "customer_id" :
"139", "template_id" : "1", "period_start": "2018-12-01 00:00:00",
"period_end": "2018-12-31 23:59:59" }'
HTTP/1.1 201 Created
Server: nginx
Date: Fri, 25 Jan 2019 14:48:32 GMT
Content-Length: 0
Connection: close
Location: /api/invoices/3
Set-Cookie: ngcp_panel_session=113b2d18ab7886024e5d5caa41b782804dd21164;
path=/; expires=Fri, 25-Jan-2019 15:48:31 GMT; HttpOnly
X-Catalyst: 5.90114
Strict-Transport-Security: max-age=15768000
You can see that body really is empty, but header Location tells where
to get generated invoice.
Please, turn attention on header "Accept" in the request when you
request generated pdf:
curl -i -X GET -H 'Connection: close' ======> -H 'Accept:
application/pdf'<======== --user administrator:administrator -k
'https://127.0.0.1:1443/api/invoices/3' > /tmp/invoice_3.pdf
Best regards,
Irina Peshinskaya
On 2019-01-25 14:36, Thomas Georg wrote:
> Hi list,
>
> I am currently trying to get the invoicing running on SPCE 6.4.1.
> Therefore I wrote the following PHP-Script:
>
> ______________________________________________________________________________________________________________________________
> // Some options
> $auth_username = 'administrator';
> $auth_password = SomePassword';
> $url = 'https://siplab:1443/api/invoices/';
> $header = array('Content-Type:
> application/json');
> $curl = curl_init();
> curl_setopt_array($curl, array(
> CURLOPT_SSL_VERIFYPEER => false,
> CURLOPT_SSL_VERIFYHOST => false,
> CURLOPT_RETURNTRANSFER => 1,
> CURLOPT_HTTPHEADER => $header,
> CURLOPT_URL => $url,
> CURLOPT_USERAGENT => 'API-Test',
> CURLOPT_HTTPAUTH=> CURLAUTH_BASIC,
> CURLOPT_USERPWD => "$auth_username:$auth_password",
> CURLOPT_POST => 1,
> CURLOPT_POSTFIELDS => json_encode(array(
> 'customer_id' => 8,
> 'template_id' => 2,
> 'period' => '2018-12'
> ))
> ));
>
> // Send the request & save response to $resp
> $resp = curl_exec($curl);
> echo "response: ".$resp;
> echo curl_error($curl);
> var_dump($resp);
>
> // Close request to clear up some resources
> curl_close($curl);
> ______________________________________________________________________________________________________________________________
>
> The invoice is created but I do not get any response from the SPCE.
>
> This is what api.log says:
>
> Jan 25 11:55:09 spce ngcp-panel: INFO: IP=my.client
> CALLED=API[POST]/api/invoices/ TX=157D1210673F6BE8 USER=administrator
> DATA={} MSG="" LOG="{"customer_id":8,"template_id":2,"period":"2018-09"}"
> Jan 25 11:55:09 spce ngcp-panel: INFO: IP=my.client CALLED=API[POST
> 201]/api/invoices/ TX=157D1210673F6BE8 USER=administrator DATA={}
> MSG="" LOG=""
>
>
> I need the response as shown in the API-Documentation to use it in
> other scripts.
> Any ideas? What am I missing?
>
> Regards
> Thomas
>
>
> _______________________________________________
> Spce-user mailing list
> Spce-user at lists.sipwise.com
> https://lists.sipwise.com/listinfo/spce-user
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sipwise.com/pipermail/spce-user_lists.sipwise.com/attachments/20190125/36956dd0/attachment-0001.html>
More information about the Spce-user
mailing list