Unable to schedule pipeline with API

278 views
Skip to first unread message

Oskar uit de Bos

unread,
Aug 13, 2017, 2:08:10 AM8/13/17
to go-cd
Hi everyone,

I am new to the go.cd platform and I am experimenting with the API. I am trying to trigger a pipeline, and after looking at the documentation (https://api.gocd.org/17.8.0/#scheduling-pipelines) it looked fairly easy to do that. However, all I am getting back is "The URL you are trying to reach appears to be incorrect.". 

My API call looks like this: curl -u admin:abc --header "Accept:application/vnd.go.cd.v5+json" -d "" http://localhost:8153/go/api/pipelines/MyFirst/schedule

I am able to get the pipeline status from the API with the following call: curl -u admin:abc --header "Accept:application/vnd.go.cd.v5+json" -d "" -Xget http://localhost:8153/go/api/pipelines/MyFirst/status
The output is : {"pausedCause":"","pausedBy":"","paused":false,"schedulable":true,"locked":false}

Anyone able to help me out with what is causing the issue? Thanks in advance.

Kind regards,
Oskar

Ganesh Patil

unread,
Aug 13, 2017, 2:37:33 AM8/13/17
to go...@googlegroups.com
Hey Oskar,

You need to specify request command to be POST and a  'Confirm: true' header.
Also, there is no need of '
Accept:application/vnd.go.cd.v5+json' api header and '-d "" ' option.

As per the documentation, the API request should be:

       -u 'admin:abc' \
       -H 'Confirm: true' \
       -X POST

Cheers,
Ganesh


--
You received this message because you are subscribed to the Google Groups "go-cd" group.
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oskar uit de Bos

unread,
Aug 13, 2017, 2:54:33 AM8/13/17
to go-cd
Hi Ganesh,

Thanks for the quick reply! I changed my API call to: curl http://localhost:8153/go/api/pipelines/MyFirst/schedule -u 'admin:abc' -H 'Confirm:true' -X POST

However, now I get a 401 unauthorized response.

What I tried myself:
- If I remove the quotes around the username:password in the curl command I get a 404 not found instead.
- Logging out and into the portal with the user. I am sure that the username & password are correct since it's the only user that there is (htpasswd file), and it's an enabled admin user. 
- Tried to look for a configuration section where I could authorize users to use the API. Didn't find anything.

Do you know what might be going on?


Kind regards,
Oskar
To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+un...@googlegroups.com.

Ganesh Patil

unread,
Aug 13, 2017, 3:36:03 AM8/13/17
to go...@googlegroups.com
Hello Oskar,

I tried accessing the API, I could curl it fine.

About the scenarios that you mentioned,
> I
f I remove the quotes around the username:password in the curl command I get a 404 not found instead.
The quotes around username:password should not matter.

Tried to look for a configuration section where I could authorize users to use the API. Didn't find anything.
There is no special authorization for the only API.
can you try accessing any other API using the same username and password? (Eg: https://api.gocd.org/17.8.0/#get-pipeline-config)

Cheers,
Ganesh



To unsubscribe from this group and stop receiving emails from it, send an email to go-cd+unsubscribe@googlegroups.com.

Oskar uit de Bos

unread,
Aug 13, 2017, 4:38:33 AM8/13/17
to go-cd
Hi Ganesh,

The following calls all return 401 unauthorized:
curl http://localhost:8153/go/api/admin/pipelines/MyFirst -u 'admin:abc' -H 'Confirm:true' -X GET
curl http://localhost:8153/go/api/pipelines/MyFirst/status -u 'admin:abc' -H 'Confirm:true' -X GET

However, when I tried the same command from a Linux client instead of the Windows machine that runs Go it worked fine. And the schedule call as well. Either the curl client I downloaded for Windows is messing something up, or the API doesn't like to be called from localhost. I suspect the curl client to be the cause. Either way, now it's just a matter of getting the API call to work on the machine, now that I know the call is correct, and there is no configuration issue in my Go instance.

Thanks for your help Ganesh, it made all the difference!

Kind regards,
Oskar

Oskar uit de Bos

unread,
Aug 13, 2017, 5:10:36 AM8/13/17
to go-cd
Hi everyone,

With the help of Ganesh I was able to pinpoint my API call problem to either the curl client that I downloaded for Windows or the fact that the API doesn't like to be called from localhost. Well, it turns out that the curl client was to blame. I created a simple Powershell script that calls the API on localhost, and it works fine. For those that that use Windows machines, her is the script:

$encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("admin:abc"))
$basicAuthValue
= "Basic $encodedCreds"


$headers
= New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers
.Add("Authorization", $basicAuthValue)
$headers
.Add("Confirm", 'true')


Invoke-WebRequest -Uri "http://localhost:8153/go/api/pipelines/MyFirst/schedule" -Headers $headers -Method Post

Kind regards,
Oskar
Reply all
Reply to author
Forward
0 new messages