Submit job with API

Post Reply
User avatar
magnussandstrom
Advanced member
Posts: 342
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Submit job with API

Post 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.
Padawan
Advanced member
Posts: 358
Joined: Mon Jun 12, 2017 8:48 pm
Location: Belgium
Contact:

Re: Submit job with API

Post 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?
User avatar
magnussandstrom
Advanced member
Posts: 342
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Submit job with API

Post by magnussandstrom »

Oh, we doesn't have the Web Service license.. :roll:

I will use a webhook instead.
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Submit job with API

Post 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?
User avatar
magnussandstrom
Advanced member
Posts: 342
Joined: Thu Jul 30, 2020 6:34 pm
Location: Sweden
Contact:

Re: Submit job with API

Post 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."}
Post Reply