problems creating test-case-folders with REST API

dbombardieri
Messages : 2
Inscription : mar. janv. 07, 2020 3:41 pm

problems creating test-case-folders with REST API

Message par dbombardieri »

Hello
I'm trying to use REST API to create a test case folder

I make a REST call to the url http: //mysquashserver/squash/api/rest/latest/test-case-folders with the POST method and 2 headers:
- Authorization basic
- Content-Type header: application/json

body is:
{
   "_type": "test-case-folder",
   "name": "Test case folder 1",
   "description": "Description Test case folder 1",
   "custom_fields": [
     {
       "code": "cuf1",
       "value": "Cuf1 Value"
     }
   ]
   "parent": {
     "_type": "project",
     "id": 18
   }
}

the folder is not created
in the body of the answer I receive the list of the folder
as if i had run the GET method

the status code that I receive in response is 0200 (OK)
instead I would have expected 0201 (created)

am I doing something wrong ?
Thanks for your help

nobody help me ?

thanks a lot. i'll never post something here.
Dernière modification par dbombardieri le lun. févr. 03, 2020 4:14 pm, modifié 2 fois.
chouaib
Messages : 2
Inscription : mer. janv. 08, 2020 12:20 am

Re: problems creating test-case-folders with REST API

Message par chouaib »

Hello,
I'm new to squash and I want to consume the rest API but there is no way to find a tutorial or an example to how it should look like. could you please helpl me I just need to know more about the Authorization basic part and how to do it.

It would be very helpful
Thank you
dbombardieri
Messages : 2
Inscription : mar. janv. 07, 2020 3:41 pm

Re: problems creating test-case-folders with REST API

Message par dbombardieri »

<<could you please helpl me I just need to know more about the Authorization basic part and how to do it.>>

for Authorization you must insert a header with
Header name=Authorization
Header value =Basic xxx

where xxx should be the following string yoursquashusername:yoursquashpassword encoded in base 64

you can use this link https://www.base64encode.org/ to encode
chouaib
Messages : 2
Inscription : mer. janv. 08, 2020 12:20 am

Re: problems creating test-case-folders with REST API

Message par chouaib »

Thanks a lot for your response that was very helpful
jpaquit
Messages : 8
Inscription : lun. juin 03, 2019 4:21 pm

Re: problems creating test-case-folders with REST API

Message par jpaquit »

Hi mates!
As REST API is fairly uncomplete, I do recommend using cookie instead of Basic Auth.
In fact, REST API won't allow you to work on every levels ; I often consumes "regular" HTTP calls (such as ${SQUASH_SERVER_URL}/test-cases/${TEST_CASE_ID}).

Here is a short snippet to generate a proper session cookie:

Code : Tout sélectionner

#!/bin/bash
### Define variables
squashtmcookiejar=/tmp/squashcookies.txt
SQUASH_SERVER_PROTO=http://
SQUASH_SERVER_DN= your.domain.name
SQUASH_SERVER_PORT=8080
SQUASH_SERVER=${SQUASH_SERVER_PROTO}${SQUASH_SERVER_DN}:${SQUASH_SERVER_PORT}
SQUASH_SERVER_URL=${SQUASH_SERVER}/squash
SQUASH_u=username
SQUASH_p=password

### Catch CSRF token and header
rm ${squashtmcookiejar}
CURL_RESPONSE=$(curl -c ${squashtmcookiejar} --silent --location --request GET "${SQUASH_SERVER_URL}/login" -w %{http_code})
HTTP_CODE=$(echo "${CURL_RESPONSE}" | tail -n1)
CSRF_TOKEN=$(printf "%s\n" "$CURL_RESPONSE" | grep -Pi '<meta[^<>]*?(name="_csrf")[^<>]*?\>' | grep -Po '(?<=content=")(.*?)(?=")')
CSRF_TOKEN_HEADER=$(printf "%s\n" "$CURL_RESPONSE" | grep -Pi '<meta[^<>]*?(name="_csrf_header")[^<>]*?\>' | grep -Po '(?<=content=")(.*?)(?=")')

 ### Login to SquashTM for cookie
CURL_RESPONSE=$(curl --silent -b ${squashtmcookiejar} -c ${squashtmcookiejar} --max-redirs 0 --location \
--request POST "${SQUASH_SERVER_URL}/login?_csrf=${CSRF_TOKEN}&username=${SQUASH_u}&password=${SQUASH_p}" \
--header "Host: ${SQUASH_SERVER_DN}:${SQUASH_SERVER_PORT}" -w %{http_code})
HTTP_CODE=$(echo "${CURL_RESPONSE}" | tail -n1)
CURL_RESPONSE=$(curl --silent -b ${squashtmcookiejar} -c ${squashtmcookiejar} --location \
--request GET "${SQUASH_SERVER_URL}/home-workspace" -w %{http_code})
HTTP_CODE=$(echo "${CURL_RESPONSE}" | tail -n1)
CURL_RESPONSE=$(curl --silent -b ${squashtmcookiejar} -c ${squashtmcookiejar} --location \
--request GET "${SQUASH_SERVER_URL}/test-case-workspace/" -w %{http_code})
HTTP_CODE=$(echo "${CURL_RESPONSE}" | tail -n1)

## Check if authentification is successful
echo "${CURL_RESPONSE}" | grep "This file is part of the Squashtest platform." > /dev/null
if [ ! "${?}" -eq 0 ]; then
    printf "\033[0;31mAuthentification unsuccessful...\033[0m\n"
else
    printf "\033[0;32mAuthentification successful !\033[0m\n"
fi
QA ninja @ easiware
Kira
Messages : 1
Inscription : ven. déc. 25, 2020 3:47 pm

Re: problems creating test-case-folders with REST API

Message par Kira »

Hello @dbombardieri,

I have the same issue with the Squash API request to create and update the campaign-folder and iteration . ( yet the other requests work well in the same way... )

did you find a solution please ?
Répondre