Page 1 sur 1

problems creating test-case-folders with REST API

Publié : mar. janv. 07, 2020 3:54 pm
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.

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

Publié : mer. janv. 08, 2020 12:24 am
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

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

Publié : mer. janv. 08, 2020 2:08 pm
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

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

Publié : jeu. janv. 09, 2020 1:12 am
par chouaib
Thanks a lot for your response that was very helpful

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

Publié : jeu. sept. 10, 2020 3:58 pm
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

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

Publié : ven. déc. 25, 2020 3:57 pm
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 ?