Confluence rest API - rest

I am trying to add a document to a Confluence page. I am using this code:
E:\APP\"curl-7.53.1"\src\curl.exe -v -S -u user:password -X POST -H "X-Atlassian-Token: no-check" -F "file=#C:\Users\srvc_mdw_dev\Desktop\conf.txt" -F "comment=this is my file" "http://confluence.example.net/rest/api/content/36375143/child/attachment"
But I get the following error:
./confNote: Unnecessary use of -X or --request, POST is already inferred.
* timeout on name lookup is not supported* Trying IPaddress...
* TCP_NODELAY set
* Connected to confluence.example.net (ip address) port 80 (#0)
* Server auth using Basic with user 'user'
> POST /rest/api/content/36375143/child/attachment HTTP/1.1
> Host: example.com> Authorization: Basic c291aGFpbC5vdWFiaUBtZXRyb2V4dGVybmFsLmZyOm1ldHJvNDU2Kg==
> User-Agent: curl/7.53.1
> Accept: */*
> X-Atlassian-Token: no-check> Content-Length: 333
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------646f724e33da0066
>
* HTTP 1.0, assume close after body< HTTP/1.0 302 Found
< Location: https://example.net/rest/api/content/36375143/child/attachment< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
* HTTP error before end of send, stop sending<
* Closing connection 0
******** EDIT ********
Once I add the - L i still get the same error and the following return too :
PS E:\powershell\script> ./conf
* timeout on name lookup is not supported
* Trying IP address...
* TCP_NODELAY set
* Connected to confluence.exemple.net (IP address) port 80 (#0)
> POST /rest/api/content/pageId/child/attachment HTTP/1.1
> Host: confluence.exemple.net
> User-Agent: curl/7.53.1
> Accept: */*
> X-Atlassian-Token: nocheck
> Content-Length: 633874
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------9448fd34591626bc
>
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Found
< Location: https://confluence.exemple.net/rest/api/content/pageId/child/attachment
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
* HTTP error before end of send, stop sending
<
* Closing connection 0
* Issue another request to this URL: 'https://confluence.exemple.net/rest/api/content/pageID/child/attachment'
* Switch from POST to GET
* timeout on name lookup is not supported
* Trying IPaddress...
* TCP_NODELAY set
* Connected to confluence.exemple.net (IPaddress) port 443 (#1)
* schannel: SSL/TLS connection with confluence.exemple.net port 443 (step 1/3)
* schannel: checking server certificate revocation
* schannel: sending initial handshake data: sending 200 bytes...
* schannel: sent initial handshake data: sent 200 bytes
* schannel: SSL/TLS connection with confluence.exemple.net port 443 (step 2/3)
* schannel: encrypted data buffer: offset 4096 length 4096
* schannel: encrypted data length: 4004
* schannel: encrypted data buffer: offset 4004 length 4096
* schannel: received incomplete message, need more data
* schannel: SSL/TLS connection with confluence.exemple.net port 443 (step 2/3)
* schannel: encrypted data buffer: offset 4865 length 5028
* schannel: next InitializeSecurityContext failed: Unknown error (0x80092013) - The revocation function was unable to ch
eck revocation because the revocation server was offline.
* Closing connection 1
* schannel: shutting down SSL/TLS connection with confluence.exemple.net port 443
* Send failure: Connection was reset
* schannel: failed to send close msg: Failed sending data to the peer (bytes written: -1)
* schannel: clear security context handle

Related

403-Forbidden at ingress controller in AKS cluster

I am trying to configure an AKS cluster and assign a DNS(say abc.com) that is bought from GoDaddy. I have configured following components:
Azure DNS zone for abc.com
Update Name-Servers generated by Azure DNS zone at GoDaddy DNS settings
Add 'DNS zone contributor' role to K8s cluster agentpool.
Setup Ingress controller, External DNS, Cert-manager, ClusterIssuer
Add Ingress route for my application
Deploy my application to setup it's Pod and service on cluster.
When I try to hit the API(https://dev.abc.com/backend/usermanager/api/user) from postman I am getting a 403-Forbidden error.
When I open a shell from ingress-controller container within the cluster and curl above API it gives same 403-Forbidden error with following details:
bash-5.1$ curl -v -d '{"name": "John Doe", "mobileNumber": "1234554321"}' -H 'Content-Type:
application/json' https://dev.abc.com/backend/usermanager/api/user
* Trying 21.81.66.166:443...
* Connected to dev.abc.com (21.81.66.166) port 443 (#0)
* ALPN: offers h2
* ALPN: offers http/1.1
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN: server accepted h2
* Server certificate:
* subject: CN=dev.abc.com
* start date: Jul 20 03:29:46 2022 GMT
* expire date: Oct 18 03:29:45 2022 GMT
* subjectAltName: host "dev.abc.com" matched cert's "dev.abc.com"
* issuer: C=US; O=Let's Encrypt; CN=R3
* SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* h2h3 [:method: POST]
* h2h3 [:path: /backend/usermanager/api/user]
* h2h3 [:scheme: https]
* h2h3 [:authority: dev.abc.com]
* h2h3 [user-agent: curl/7.83.1]
* h2h3 [accept: */*]
* h2h3 [content-type: application/json]
* h2h3 [content-length: 50]
* Using Stream ID: 1 (easy handle 0x64161d71800)
> POST /backend/usermanager/api/user HTTP/2
> Host: dev.abc.com
> user-agent: curl/7.83.1
> accept: */*
> content-type: application/json
> content-length: 50
>
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
* old SSL session ID is stale, removing
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
* We are completely uploaded and fine
< HTTP/2 403
< date: Fri, 22 Jul 2022 04:40:59 GMT
< content-length: 0
< vary: Origin
< vary: Access-Control-Request-Method
< vary: Access-Control-Request-Headers
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< pragma: no-cache
< expires: 0
< strict-transport-security: max-age=15724800; includeSubDomains
< x-frame-options: DENY
<
* Connection #0 to host dev.abc.com left intact
bash-5.1$ * We are completely uploaded and fine
< HTTP/2 403
< date: Fri, 22 Jul 2022 04:40:59 GMT
< content-length: 0
< vary: Origin
< vary: Access-Control-Request-Method
< vary: Access-Control-Request-Headers
< x-content-type-options: nosniff
< x-xss-protection: 1; mode=block
< cache-control: no-cache, no-store, max-age=0, must-revalidate
< pragma: no-cache
< expires: 0
< strict-transport-security: max-age=15724800; includeSubDomains
< x-frame-options: DENY
When I curl the above endpoint directly with the service name as host within a shell from ingress-controller container, it works properly:
bash-5.1$ curl -v -d '{"name": "John Doe", "mobileNumber": "1234554321"}' -H 'Content-Type: application/json' http://usermanager:8082/api/user
* Trying 10.0.236.14:8082...
* Connected to usermanager (10.0.236.14) port 8082 (#0)
> POST /api/user HTTP/1.1
> Host: usermanager:8082
> User-Agent: curl/7.83.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 50
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Fri, 22 Jul 2022 03:58:33 GMT
Following is my ingress route config:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: abc-ingress
namespace: k8sns-abc-dev
annotations:
kubernetes.io/ingress.class: "nginx"
cert-manager.io/cluster-issuer: letsencrypt
spec:
tls:
- hosts:
- dev.abc.com
secretName: tls-secret
rules:
- host: dev.abc.com
http:
paths:
- path: /backend/usermanager
pathType: Prefix
backend:
service:
name: usermanager
port:
number: 8082
Can you please help me identify and fix why am I getting 403-Forbidden error when making an API request through DNS host?
When you are hitting the path https://dev.abc.com/backend/usermanager/api/user
and when you are trying the API inside of container, the path is api/user
Inside your ingress, there is no path re-write config.
So i think your service will be getting the path backend/usermanager/api/user
However, 403 is for unauth so make sure there is no another path logic check or so.

"Given request parameters are null or invalid" when using curl to submit URLs with IndexNow API

I try to submit URLs to the Bing search engine through IndexNow API using cURL, but I get an "invalid parameter" error, how to fix it?
Here is the PowerShell script
$header_host = '"Host: www.bing.com"'
$header_content = '"Content-Type: application/json; charset=utf-8"'
$url_index =
'"https://www.bing.com/IndexNow"'
$data = '{
"host": "xinlake.dev",
"key": "72d80bb8d9f645ad9e246e46d336c997",
"keyLocation": "https://xinlake.dev/72d80bb8d9f645ad9e246e46d336c997.txt",
"urlList": [
"https://xinlake.dev/blog/2022/05-voting-script/",
"https://xinlake.dev/blog/2022/05-private-channel/"
]
}'
& curl.exe -v --http1.1 --header $header_host --header $header_content --data $data $url_index
""
Here is the error log
* Trying 202.89.233.100:443...
* Connected to www.bing.com (202.89.233.100) port 443 (#0)
* schannel: disabled automatic use of client certificate
* schannel: ALPN, offering http/1.1
* schannel: ALPN, server accepted to use http/1.1
> POST /IndexNow HTTP/1.1
> Host: www.bing.com
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json; charset=utf-8
> Content-Length: 278
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Length: 92
< Content-Type: application/json; charset=utf-8
< Expires: -1
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< X-Cache: CONFIG_NOCACHE
< Accept-CH: Sec-CH-UA-Arch, Sec-CH-UA-Bitness, Sec-CH-UA-Full-Version, Sec-CH-UA-Mobile, Sec-CH-UA-Model, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version
< X-MSEdge-Ref: Ref A: C06F23F2577843719494581907366B26 Ref B: BJ1EDGE0917 Ref C: 2022-06-15T10:20:00Z
< Date: Wed, 15 Jun 2022 10:20:00 GMT
<
{"code":"InvalidRequestParameters","message":"Given request parameters are null or invalid"}* Connection #0 to host www.bing.com left intact
Thanks, I have solved this by posting a JSON file.
Script changes
$data = '"path to the json file"'
& curl.exe -v --http1.1 --header $header_host --header $header_content --data #$data $url_index
JSON file
{
"host": "xinlake.dev",
"key": "72d80bb8d9f645ad9e246e46d336c997",
"keyLocation": "https://www.xinlake.dev/72d80bb8d9f645ad9e246e46d336c997.txt",
"urlList": [
"https://www.xinlake.dev/blog/2022/05-voting-script/",
"https://www.xinlake.dev/blog/2022/05-private-channel/"
]
}
Request and response
* Trying 202.89.233.101:443...
* Connected to www.bing.com (202.89.233.101) port 443 (#0)
* schannel: disabled automatic use of client certificate
* schannel: ALPN, offering http/1.1
* schannel: ALPN, server accepted to use http/1.1
> POST /IndexNow HTTP/1.1
> Host: www.bing.com
> User-Agent: curl/7.79.1
> Accept: */*
> Content-Type: application/json; charset=utf-8
> Content-Length: 302
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Cache-Control: no-cache
< Pragma: no-cache
< Expires: -1
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< X-Cache: CONFIG_NOCACHE
< Accept-CH: Sec-CH-UA-Arch, Sec-CH-UA-Bitness, Sec-CH-UA-Full-Version, Sec-CH-UA-Mobile, Sec-CH-UA-Model, Sec-CH-UA-Platform, Sec-CH-UA-Platform-Version
< X-MSEdge-Ref: Ref A: C9107410449C4D1A837A53C5CB1D392C Ref B: BJ1EDGE0416 Ref C: 2022-06-15T14:11:21Z
< Date: Wed, 15 Jun 2022 14:11:21 GMT
< Content-Length: 0
<
* Connection #0 to host www.bing.com left intact

how to split http response in Swift using boundary from Content-Type header param

This is the verbose output using curl to request the server
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 55254 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:55254
> User-Agent: curl/7.64.1
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Server: WDA MJPEG Server
< Connection: close
< Max-Age: 0
< Expires: 0
< Cache-Control: no-cache, private
< Pragma: no-cache
< Content-Type: multipart/x-mixed-replace; boundary=--BoundaryString
<
I am new to Swift and have some difficulties in finding libraries to read the http response and split it using the boundary param found in Content-Type, I know in golang, we can use the multipart.Reader
multipartReader := multipart.NewReader(resp.Body, boundary)
multipartReader.NextPart()
how do I achieve the same in swift?

Empty response from Bitstamp.net

I am trying to use the private api from Bitstamp to query for my account's balance. I believe I am posting the right data as no error is returned but Bitstamp's answer is always empty
* Trying 107.154.249.133...
* Connected to www.bitstamp.net (107.154.249.133) port 443 (#0)
* ALPN, offering http/1.1
* Cipher selection:
ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:#STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/certs/ca-certificates.crt
CApath: /etc/ssl/certs
* NPN, negotiated HTTP1.1
* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: OU=Domain Control Validated; CN=*.bitstamp.net
* start date: Apr 8 14:11:39 2015 GMT
* expire date: Apr 8 15:48:13 2018 GMT
* subjectAltName: www.bitstamp.net matched
* issuer: C=US; ST=Arizona; L=Scottsdale; O=GoDaddy.com, Inc.;
OU=http://certs.godaddy.com/repository/; CN=Go Daddy Secure Certificate
Authority - G2
* SSL certificate verify ok.
> POST /api/v2/balance HTTP/1.1
Host: www.bitstamp.net
User-Agent: Bitstamp C++ API Client
Accept: */*
Content-Length: 134
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 134 out of 134 bytes
< HTTP/1.1 301 MOVED PERMANENTLY
< Access-Control-Allow-Headers: x-requested-with, Content-Type, origin, accept, cache-control
< Access-Control-Allow-Methods: POST, GET
< Access-Control-Allow-Origin: *
< Content-Language: en
< Content-Type: text/html; charset=utf-8
< Date: Fri, 08 Sep 2017 17:46:41 GMT
< Location: http://www.bitstamp.net/api/v2/balance/
< Server: Apache
< Strict-Transport-Security: max-age=63072000; includeSubDomains
< Vary: Accept-Language
< X-Frame-Options: SAMEORIGIN
< Content-Length: 0
< Connection: keep-alive
< Set-Cookie: visid_incap_99025=wHhR5uPzT92ReB9XbeNToIHXslkAAAAAQUIPAAAAAAAbNQJEog5ZojcqdOv0dFhd; expires=Sat, 08 Sep 2018 10:32:13 GMT; path=/; Domain=.bitstamp.net
< Set-Cookie: nlbi_99025=VyBXXwUOsQHckThX8F1n9AAAAABOW3tLZ0nUHyp47yinIimv; path=/; Domain=.bitstamp.net
< Set-Cookie: incap_ses_569_99025=04PeXe3KGFAAVw//8n7lB4HXslkAAAAA09BkGnsaiskl2dkFxzhFXQ==; path=/; Domain=.bitstamp.net
< X-Iinfo: 9-15073063-15060114 PNNN RT(1504892800858 31) q(0 0 0 -1) r(2 2) U6
< X-CDN: Incapsula
<
* Connection #0 to host www.bitstamp.net left intact
result: 0
response:
terminate called after throwing an instance of 'std::runtime_error'
what(): Bitstamp response doesn't contain result data
Any idea ?
Thanks a lot in advance !
Initially I had the balance path to be /balance, but after changing to /balance/ it worked and got 200 back with payload.
So instead of http://www.bitstamp.net/api/v2/balance use http://www.bitstamp.net/api/v2/balance/, note the trailing backslash

SoundCloud and WWW::Curl::Form - 404 Not found

script that changes description of a track. I'm getting 404 error.
Token and url are valid (works from the command line)
sample:
curl -X PUT "https://api.soundcloud.com/tracks/45272532.json" -F 'oauth_token=12345678' -F 'track[description]=This track was recorded in Berlin.'
script:
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Curl::Easy;
use WWW::Curl::Form;
my $curl = new WWW::Curl::Easy();
$curl->setopt( CURLOPT_VERBOSE, 1 );
$curl->setopt( CURLOPT_NOSIGNAL, 1 );
$curl->setopt( CURLOPT_HEADER, 1 );
$curl->setopt( CURLOPT_TIMEOUT, 10 );
$curl->setopt( CURLOPT_URL, 'https://api.soundcloud.com/tracks/45272532.json' );
my $curlf = new WWW::Curl::Form();
$curlf->formadd( 'oauth_token', 12345678' );
$curlf->formadd( 'track[description]', 'This track was recorded in Berlin.' );
$curl->setopt( CURLOPT_HTTPPOST, $curlf );
my $resp = '';
open( my $resp_fh, ">", \$resp );
$curl->setopt( CURLOPT_WRITEDATA, $resp_fh );
my $retcode = $curl->perform();
die($retcode) if ( $retcode != 0 );
print $resp;
response:
* About to connect() to api.soundcloud.com port 443 (#0)
* Trying 178.249.136.151... * connected
* Connected to api.soundcloud.com (178.249.136.151) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL connection using DHE-RSA-AES256-SHA
* Server certificate:
* subject: C=DE; OU=Domain Control Validated; O=api.soundcloud.com; CN=api.soundcloud.com
* start date: 2010-08-26 10:42:17 GMT
* expire date: 2013-09-18 23:59:59 GMT
* subjectAltName: api.soundcloud.com matched
* issuer: C=BE; OU=Domain Validation CA; O=GlobalSign nv-sa; CN=GlobalSign Domain Validation CA
* SSL certificate verify ok.
> POST /tracks/45272532.json HTTP/1.1
Host: api.soundcloud.com
Accept: */*
Content-Length: 319
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------5e3965475f60
< HTTP/1.1 100 Continue
< HTTP/1.1 404 Not Found
< Server: nginx
< Date: Sat, 05 May 2012 13:25:50 GMT
< Content-Type: application/xml; charset=utf-8
< Connection: keep-alive
< Cache-Control: no-cache
< X-Runtime: 8
< Access-Control-Allow-Methods: GET, PUT, POST, DELETE
< Access-Control-Allow-Headers: Accept, Authorization, Content-Type, Origin
< Access-Control-Allow-Origin: *
< X-Cacheable: NO:Cache-Control=no-cache
< Content-Length: 30
< X-Varnish: 1799105788
< Age: 0
< Via: 1.1 varnish
< X-Cache: MISS
<
* Connection #0 to host api.soundcloud.com left intact
* Closing connection #0
thank you
Radek
> POST /tracks/45272532.json HTTP/1.1
fail.^^^^
$curl->setopt( CURLOPT_PUT, 1 );