Page 1 of 1
Submit job with API
Posted: Fri Nov 18, 2022 10:29 pm
by magnussandstrom
I am trying to submit a job to a switch flow (that starts with a submit point) with the switch API.
Login works fine, I get response:
{
"token": "ff236acd25452401244a38e0a7200fbfa85c1***",
"user": "****",
"messagesAccess": true,
"jobClientAccess": true,
"jobFinderAccess": true,
"viewBoardsAccess": true,
"administratorAccess": true,
"reportingAccess": false,
"webservicesAccess": false,
"success": true
}
But when trying to submit a job I get:
{"status":false,"error":"Cannot submit a job."}
What could be causing this?
The user is set to administrator with all access to ”everything” in the switch user tab.
Re: Submit job with API
Posted: Sat Nov 19, 2022 2:25 pm
by Padawan
I assume you did use the token you received from the login api call in your subsequent calls?
This is the relevant extract from the documentation:
The token must be put in the HTTP Authorization header for each subsequent REST call, so the header looks like: Authorization: Bearer ab43e62fbbd5ea541efbbb79c74e5d1c7411c6f6
Also, I can't find a permission setting for a user in Switch which makes webservicesAccess set to false while jobClientAccess is true.
If you create a new user and test with that, do you have the same issue?
Re: Submit job with API
Posted: Sun Nov 20, 2022 11:41 am
by magnussandstrom
Oh, we doesn't have the Web Service license..
I will use a webhook instead.
Re: Submit job with API
Posted: Mon Nov 21, 2022 8:31 am
by freddyp
You do not need the Web Services Module to talk to Switch's REST API, so that is not the reason it does not work. What the reason is, I am not sure. My first thought is a user setting, but you rule that out. Do you have the Switch Client Module?
Re: Submit job with API
Posted: Mon Nov 21, 2022 10:07 am
by magnussandstrom
freddyp wrote: ↑Mon Nov 21, 2022 8:31 am
You do not need the Web Services Module to talk to Switch's REST API, so that is not the reason it does not work. What the reason is, I am not sure. My first thought is a user setting, but you rule that out. Do you have the Switch Client Module?
Yes, we have 15 Client licenses.
This is the complete call from postman:
Code: Select all
Request:
Method: POST, RequestUri: 'https://switch.tabergmediagroup.se:51088/api/v1/job', Version: 1.1, Content: System.Net.Http.MultipartFormDataContent, Headers:
{
Accept: application/json
Authorization: Bearer 1610a1aca91f19c979a36338ce2694c27e154ec6
Content-Type: multipart/form-data; boundary="b36059c8-e423-436c-9787-0f3e56e0c5d7"
}
--b36059c8-e423-436c-9787-0f3e56e0c5d7
Content-Disposition: form-data; name=flowId
276
--b36059c8-e423-436c-9787-0f3e56e0c5d7
Content-Disposition: form-data; name=objectId
109
--b36059c8-e423-436c-9787-0f3e56e0c5d7
Content-Disposition: form-data; name=jobName
TurboTest
--b36059c8-e423-436c-9787-0f3e56e0c5d7
Content-Disposition: form-data; name=metadata
[{"id":"spMF_1","name":"Kontaktperson","value":test1@test.se},{"id":"spMF_2","name":"Jobbnamn","value":"TurboTest"},{"id":"spMF_3","name":"Förnamn","value":"Namn"},{"id":"spMF_4","name":"Efternamn","value":"Namnsson"},{"id":"spMF_5","name":"Företag","value":"TEST job"},{"id":"spMF_6","name":"E-post","value":test2@test.se},{"id":"spMF_7","name":"Telefon","value":"023456789"},{"id":"spMF_8","name":"Personuppgift_GDPR","value":"No"},{"id":"spMF_9","name":"Meddelande","value":"Testing a bit"},{"id":"spMF_10","name":"jobID","value":"e4dec985-a8c2-4a5f-932c-a79a6b5a6a5c"}]
--b36059c8-e423-436c-9787-0f3e56e0c5d7
Content-Disposition: form-data; name="file[0][path]"
e4dec985-a8c2-4a5f-932c-a79a6b5a6a5c.txt
--b36059c8-e423-436c-9787-0f3e56e0c5d7
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name="file[0][file]"
e4dec985-a8c2-4a5f-932c-a79a6b5a6a5c
--b36059c8-e423-436c-9787-0f3e56e0c5d7--
Response:
StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers:
{
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization
Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS
Cache-Control: private, no-cache, no-store, must-revalidate
Pragma: no-cache
ETag: W/"2f-StrEddQJqTZlgiB/E273hOluPWU"
Date: Fri, 18 Nov 2022 21:13:17 GMT
Connection: keep-alive
Keep-Alive: timeout=300
Expires: -1
Content-Type: application/json; charset=utf-8
Content-Length: 47
}
{"status":false,"error":"Cannot submit a job."}